示例#1
0
        private Program()
        {
            ThreadExit += OnProgramExit;

            _notifyIcon = new NotifyIcon
            {
                Text             = AssemblyUtil.ProductName(),
                Icon             = Resources.Icon,
                Visible          = true,
                ContextMenuStrip = new ContextMenuStrip
                {
                    Items =
                    {
                        (_currentImageLabel = new ToolStripLabel()),
                        (_currentIndexLabel = new ToolStripLabel()),
                        new ToolStripSeparator(),
                        new ToolStripButton(Resources.Program_Program_Previous_Wallpapaper, null, OnPreviousImageClick),
                        new ToolStripButton(Resources.Program_Program_Next_Wallpaper, null, OnNextImageClick),
                        new ToolStripSeparator(),
                        new ToolStripButton(Resources.Program_Program_Settings, null, OnSettingsButtonClick),
                        new ToolStripButton(Resources.Program_Program_Exit, null, OnCloseButtonClick)
                    }
                }
            };

            _currentImageLabel.Font = new Font(_currentImageLabel.Font, FontStyle.Bold);

            // open context menu strip on click
            _notifyIcon.Click += (sender, args) => _notifyIcon.ShowContextMenu();

            // start watching
            _watchThread = new Thread(WatchThread);
            _watchThread.Start();
        }
示例#2
0
 private void TrayIcon_MouseUp(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         BuildContextMenu();
         TrayIcon.ShowContextMenu();
     }
 }
示例#3
0
        private void ExecuteTrayBehavior(TrayIconBehavior behavior)
        {
            switch (behavior)
            {
            case TrayIconBehavior.ContextMenu:
                NotifyIcon.ShowContextMenu(Hardcodet.Wpf.TaskbarNotification.Util.GetMousePosition(NotifyIcon));
                break;

            case TrayIconBehavior.ShowHide:
                ShowHide(null, null);
                break;
            }
        }
        private void TrayIcon_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                #region Network DNS

                List <IPAddress> networkDnsAddresses = new List <IPAddress>();

                try
                {
                    foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
                    {
                        if (nic.OperationalStatus != OperationalStatus.Up)
                        {
                            continue;
                        }

                        networkDnsAddresses.AddRange(nic.GetIPProperties().DnsAddresses);
                    }
                }
                catch
                { }

                NetworkDnsMenuItem.DropDownItems.Clear();
                NetworkDnsMenuItem.DropDownItems.Add(DefaultNetworkDnsMenuItem);
                NetworkDnsMenuItem.DropDownItems.Add(new ToolStripSeparator());

                bool noItemChecked = true;
                DefaultNetworkDnsMenuItem.Checked = false;

                foreach (DnsProvider dnsProvider in _dnsProviders)
                {
                    ToolStripMenuItem item = new ToolStripMenuItem(dnsProvider.Name);
                    item.Tag    = dnsProvider;
                    item.Click += NetworkDnsMenuSubItem_Click;

                    if (AddressExists(networkDnsAddresses, dnsProvider.Addresses))
                    {
                        item.Checked  = true;
                        noItemChecked = false;
                    }

                    NetworkDnsMenuItem.DropDownItems.Add(item);
                }

                if (noItemChecked)
                {
                    foreach (IPAddress dnsAddress in networkDnsAddresses)
                    {
                        if (!dnsAddress.IsIPv6SiteLocal)
                        {
                            DefaultNetworkDnsMenuItem.Checked = true;
                            break;
                        }
                    }
                }

                if (_dnsProviders.Count > 0)
                {
                    NetworkDnsMenuItem.DropDownItems.Add(new ToolStripSeparator());
                }

                NetworkDnsMenuItem.DropDownItems.Add(ManageNetworkDnsMenuItem);

                #endregion

                #region service

                try
                {
                    _service.Refresh();

                    switch (_service.Status)
                    {
                    case ServiceControllerStatus.Stopped:
                        DashboardMenuItem.Enabled      = false;
                        StartServiceMenuItem.Enabled   = true;
                        RestartServiceMenuItem.Enabled = false;
                        StopServiceMenuItem.Enabled    = false;
                        break;

                    case ServiceControllerStatus.Running:
                        DashboardMenuItem.Enabled      = true;
                        StartServiceMenuItem.Enabled   = false;
                        RestartServiceMenuItem.Enabled = true;
                        StopServiceMenuItem.Enabled    = true;
                        break;

                    default:
                        DashboardMenuItem.Enabled      = false;
                        StartServiceMenuItem.Enabled   = false;
                        RestartServiceMenuItem.Enabled = false;
                        StopServiceMenuItem.Enabled    = false;
                        break;
                    }

                    ServiceMenuItem.Enabled = true;
                }
                catch
                {
                    DashboardMenuItem.Enabled = false;
                    ServiceMenuItem.Enabled   = false;
                }

                #endregion

                #region auto start

                try
                {
                    using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true))
                    {
                        if (key != null)
                        {
                            string autoStartPath = key.GetValue("Technitium DNS System Tray") as string;

                            AutoStartMenuItem.Checked = (autoStartPath != null) && autoStartPath.Equals("\"" + Program.APP_PATH + "\"");
                        }
                    }
                }
                catch
                { }

                #endregion

                TrayIcon.ShowContextMenu();
            }
        }