void cMenu_PreviewKeyDown(object sender, System.Windows.Forms.PreviewKeyDownEventArgs e) { if (e.KeyCode == System.Windows.Forms.Keys.Back) { cMenu.Close(); } }
private void InitializeNotifyIcon() { _notifyIcon = new System.Windows.Forms.NotifyIcon { Text = App.reCLIName, Icon = reCLI.Properties.Resources.app, Visible = true }; var menu = new System.Windows.Forms.ContextMenuStrip(); var items = menu.Items; _notifyIcon.DoubleClick += (o, e) => MainViewModel.Current.MainWindowVisibility = Visibility.Visible; var open = items.Add("打开"); open.Click += (o, e) => MainViewModel.Current.MainWindowVisibility = Visibility.Visible; var exit = items.Add("退出"); exit.Click += (o, e) => MainWindow.Close(); _notifyIcon.ContextMenuStrip = menu; _notifyIcon.MouseClick += (o, e) => { if (e.Button == System.Windows.Forms.MouseButtons.Left) { if (menu.Visible) { menu.Close(); } else { var p = System.Windows.Forms.Cursor.Position; menu.Show(p); } } }; }