Exemple #1
0
        public static void Start()
        {
            _contextMenu = new ContextMenu();

            var openMenuItem = new MenuItem("Show");

            openMenuItem.Click += (s, e) => Show?.Invoke(null, EventArgs.Empty);
            _contextMenu.MenuItems.Add(openMenuItem);

            _contextMenu.MenuItems.Add(new MenuItem("-"));

            var checkUpdatesMenuItem = new MenuItem("Check Updates");

            checkUpdatesMenuItem.Click += (s, e) => CheckUpdates?.Invoke(null, EventArgs.Empty);
            _contextMenu.MenuItems.Add(checkUpdatesMenuItem);

            var aboutMenuItem = new MenuItem("About RoboChat...");

            aboutMenuItem.Click += (s, e) => About?.Invoke(null, EventArgs.Empty);
            _contextMenu.MenuItems.Add(aboutMenuItem);

            _contextMenu.MenuItems.Add(new MenuItem("-"));

            var closeMenuItem = new MenuItem("Exit");

            closeMenuItem.Click += (s, e) => App.Current.Shutdown();
            _contextMenu.MenuItems.Add(closeMenuItem);

            _notifyIcon = new NotifyIcon()
            {
                Icon        = Properties.Resources.RoboChat32,
                ContextMenu = _contextMenu,
                Text        = Settings.Instance.Name,
                Visible     = true
            };

            _notifyIcon.MouseClick += (s, e) =>
            {
                if (e.Button != MouseButtons.Left)
                {
                    return;
                }

                if (Toggle == null)
                {
                    Message(ToolTipIcon.Warning, "Application is closing. Please wait...");
                }

                Toggle?.Invoke(null, EventArgs.Empty);
            };
            _notifyIcon.BalloonTipClicked += _notifyIcon_BalloonTipClicked;
        }
Exemple #2
0
        private static void _notifyIcon_BalloonTipClicked(object sender, EventArgs e)
        {
            // Если это системное сообщение
            if (_notifyIcon.BalloonTipTitle == Settings.TitleUpdate)
            {
                CheckUpdates?.Invoke(null, EventArgs.Empty);
            }

            string windowTitle = _notifyIcon.Tag as string;

            if (windowTitle != null && windowTitle.Length > 0)
            {
                OpenWindow?.Invoke(null, new WindowEventArgs(windowTitle));
            }
        }