using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Drawing; using System.Resources; namespace Systrayicon { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class RegistrationWindow : Window { private System.Windows.Forms.NotifyIcon _notifyIcon = null; private System.Windows.Controls.ContextMenu _mContextMenu; public RegistrationWindow() { InitializeComponent(); _mContextMenu = new System.Windows.Controls.ContextMenu(); if (null == _notifyIcon) { _notifyIcon = new System.Windows.Forms.NotifyIcon { Icon = new Icon(@"D:\WPFSystemTray\Images\RedOrb.ico"), Visible = true }; _notifyIcon.MouseUp += new System.Windows.Forms.MouseEventHandler(NotifyIconMouseUp); } } private void Window_Closed(object sender, EventArgs e) { this._notifyIcon.Dispose(); } void NotifyIconMouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { bool CreateTrayMenu = false; CreateTrayMenu = true; // Check if any modal dialog is visible or not //if (true == CreateTrayMenu) { if (e.Button == System.Windows.Forms.MouseButtons.Right) { MenuItem menuShow = new MenuItem(); menuShow.Header = "ShowAppClick"; // menuShow.Click += new RoutedEventHandler(ShowAppClick); MenuItem menuCloseApplication = new MenuItem(); menuCloseApplication.Header = "CloseAppClick"; //menuCloseApplication.Click += new RoutedEventHandler(CloseAppClick); _mContextMenu.Items.Add(menuShow); _mContextMenu.Items.Add(menuCloseApplication); _mContextMenu.IsOpen = true; _mContextMenu.IsKeyboardFocusWithinChanged += new DependencyPropertyChangedEventHandler(_mContextMenu_IsEnabledChanged); _mContextMenu.LostFocus += new RoutedEventHandler(_mContextMenu_LostFocus); } } } void _mContextMenu_LostFocus(object sender, RoutedEventArgs e) { //throw new NotImplementedException(); _mContextMenu.IsOpen = false; } protected override void OnStateChanged(EventArgs e) { int j = 0; ++j; } void _mContextMenu_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) { //throw new NotImplementedException(); _mContextMenu.IsOpen = false; } //protected override void Dispose(bool disposing) //{ // if (disposing) // { // this._notifyIcon.Dispose(); // } //} } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)