I created a menu for my TrayIcon
:
Butiftheuserdoesnotselectanoptionitisstillvisible.WouldanyoneknowhowIcanhideincasetheuserclicksoutsidethemenuarea?
Here'sthecodeI'musingtoparsethemenu:
System.Windows.Forms.NotifyIconiconeTaskBar=null;privatevoidConfigurarIconeTaskBar(){iconeTaskBar=newSystem.Windows.Forms.NotifyIcon();StreamiconStream=Application.GetResourceStream(newUri("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;
}
}