示例#1
0
        private static void AddServicesToTrayContextMenu()
        {
            int status = 0;

            for (int index = 0; index < Services.Count; index++)
            {
                var serviceController = Services[index];
                serviceController.Refresh();

                var menuItem = new ServiceMenuItem(serviceController.DisplayName)
                {
                    Service = serviceController
                };
                if (serviceController.Status == ServiceControllerStatus.Running)
                {
                    status++;
                    menuItem.Image = Properties.Resources.GreenLight.ToBitmap();
                }
                else
                {
                    menuItem.Image = Properties.Resources.RedLight.ToBitmap();
                }
                menuItem.Status = serviceController.Status;
                menuItem.Click += ServiceItemClick;
                _trayContextMenu.Items.Insert(index, menuItem);
            }
            SetIcon(status);
            if (Services.Count > 0)
            {
                _trayContextMenu.Items.Insert(Services.Count, new ToolStripSeparator());
            }
        }
示例#2
0
        private static void AddServicesToTrayContextMenu()
        {
            int status = 0;
            for (int index = 0; index < Services.Count; index++)
            {
                var serviceController = Services[index];
                serviceController.Refresh();

                var menuItem = new ServiceMenuItem(serviceController.DisplayName) { Service = serviceController };
                if (serviceController.Status == ServiceControllerStatus.Running)
                {
                    status++;
                    menuItem.Image = Properties.Resources.GreenLight.ToBitmap();
                }
                else
                {
                    menuItem.Image = Properties.Resources.RedLight.ToBitmap();
                }
                menuItem.Status = serviceController.Status;
                menuItem.Click += ServiceItemClick;
                _trayContextMenu.Items.Insert(index, menuItem);
            }
            SetIcon(status);
            if (Services.Count > 0)
            {
                _trayContextMenu.Items.Insert(Services.Count, new ToolStripSeparator());
            }
        }