public SwitcherNotificationIcon(HostSwitcher hosts)
        {
            _contextMenu = new ContextMenuStrip
                {
                    Name = "contextMenu",
                    Size = new System.Drawing.Size(109, 26)
                };

            var icon = new NotifyIcon
                {
                    ContextMenuStrip = this._contextMenu,
                    Icon = new Icon("Icon.ico"),
                    Text = "Host Switcher",
                    Visible = true
                };

            AddHosts(hosts);

            _contextMenu.Items.Add(new ToolStripSeparator());

            var exit = new ToolStripMenuItem("Exit");
            exit.Click += (s, a) =>
                {
                    icon.Visible = false;
                    Application.Exit();
                };
            _contextMenu.Items.Add(exit);
        }
예제 #2
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     var hosts = new HostSwitcher();
     var icon = new SwitcherNotificationIcon(hosts);
     Application.Run();
 }
        void AddHost(HostSwitcher switcher, Host host)
        {
            var menuItem = new ToolStripMenuItem
                {
                    Text = (string.IsNullOrWhiteSpace(host.Identifier) ? host.Hostname : host.Identifier),
                    Checked = host.Enabled
                };

            menuItem.Click += (s, a) =>
                {
                    host.Enabled = !menuItem.Checked;
                    menuItem.Checked = host.Enabled;
                    switcher.Save();
                };

            _contextMenu.Items.Add(menuItem);
        }
 void AddHosts(HostSwitcher hosts)
 {
     foreach (var host in hosts.Hosts)
         AddHost(hosts, host);
 }