2
I created a menu for my TrayIcon
:
However, if the user does not select an option, it is still visible. Would anyone know how to hide if the user clicks outside the menu area?
Here’s the code I’m using for the menu:
System.Windows.Forms.NotifyIcon iconeTaskBar = null;
private void ConfigurarIconeTaskBar()
{
iconeTaskBar = new System.Windows.Forms.NotifyIcon();
Stream iconStream = Application.GetResourceStream(new Uri("pack://application:,,,/IMG;component/Imagens/locationICO.ico")).Stream;
iconeTaskBar.Icon = new System.Drawing.Icon(iconStream);
iconeTaskBar.DoubleClick += iconeTaskBar_DoubleClick;
iconeTaskBar.Text = "IMG";
iconeTaskBar.MouseDown += new System.Windows.Forms.MouseEventHandler(iconeTaskBar_MouseDown);
}
private void iconeTaskBar_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
ContextMenu menu = new ContextMenu();
MenuItem menuItemVouPara = new MenuItem() { Header = "Cadastrar saída" };
menuItemVouPara.Click += menuItemVouPara_Click;
menuItemVouPara.Icon = new System.Windows.Controls.Image
{ Source = new BitmapImage(new Uri("pack://application:,,,/Imagens/voupara.png", UriKind.Absolute)) };
menu.Items.Add(menuItemVouPara);
menu.IsOpen = true;
}
}
Trayicon with WPF? What api are you using?
– ramaral
None, I did with c# using reference to
TrayIcon
windows Forms.– MeuChapeu
@ramaral, I did more or less like this on this site --> https://ebbypeter.wordpress.com/2010/06/28/minimize-a-wpf-application-to-system-tray-in-c/
– MeuChapeu
If you’re wearing one System.Windows.Forms.Contextmenu() and then associates it with Notifyicon through
NotifyIcon.ContextMenu
, the Contextmenu should close by him.– ramaral
@ramaral, I added the code to the question, how I’m doing to create the menu.
– MeuChapeu