Functions to modify system values using WMI.
        private void ContextMenuPopup(object sender, EventArgs e)
        {
            // update the slider to the current brightness
            var currentBrightness = WmiFunctions.GetBrightnessLevel();

            mnuLabel.Text = "Brightness: " + currentBrightness + "%";
        }
        /// <summary>
        /// Window activated method. Sets the window border colour if the DWM is disabled.
        /// </summary>
        /// <param name="sender">The sender of the message.</param>
        /// <param name="e">Event arguments.</param>
        private void Window_Activated(object sender, EventArgs e)
        {
            // update the slider to the current brightness
            ignoreValueChanged = true;
            UpdateUI(WmiFunctions.GetBrightnessLevel());
            ignoreValueChanged = false;

            if (!Compatibility.IsDWMEnabled)
            {
                this.SetNonGlassBorder(true);
            }
        }
        /// <summary>
        /// Window activated method. Sets the window border colour if the DWM is disabled.
        /// </summary>
        /// <param name="sender">The sender of the message.</param>
        /// <param name="e">Event arguments.</param>
        private void Window_Activated(object sender, EventArgs e)
        {
            // update the slider to the current brightness
            var currentBrightness = WmiFunctions.GetBrightnessLevel();

            BrightnessSlider.Value = currentBrightness;

            if (!Compatibility.IsDWMEnabled)
            {
                this.SetNonGlassBorder(true);
            }
        }
        /// <summary>
        /// Change the monitor brightness when the slider value changes.
        /// </summary>
        private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            var newBrightness = (int)e.NewValue;

            // Change the brightness in a background thread to avoid UI blocking
            new Thread((data) =>
            {
                WmiFunctions.SetBrightnessLevel((int)newBrightness);
            }).Start();

            this.percentageLabel.Content = newBrightness.ToString() + "%";
            DrawIcon.updateNotifyIcon(NotifyIcon, newBrightness);
        }
        /// <summary>
        /// Creates notify icon and menu.
        /// </summary>
        private void CreateNotifyIcon()
        {
            System.Windows.Forms.NotifyIcon notifyicon;

            notifyicon = new System.Windows.Forms.NotifyIcon();
            var currentBrightness = WmiFunctions.GetBrightnessLevel();

            //System.Windows.Forms.MenuItem mnuPin = new System.Windows.Forms.MenuItem("Pin", new EventHandler(this.PinMenuEventHandler));
            System.Windows.Forms.MenuItem mnuMonitorOff  = new System.Windows.Forms.MenuItem("Power off display", new EventHandler(this.MonitorOffMenuEventHandler));
            System.Windows.Forms.MenuItem mnuScreenSaver = new System.Windows.Forms.MenuItem("Start screen saver", new EventHandler(this.StartScreenSaverMenuEventHandler));
            System.Windows.Forms.MenuItem mnuSleep       = new System.Windows.Forms.MenuItem("Enter sleep mode", new EventHandler(this.SleepMenuEventHandler));
            System.Windows.Forms.MenuItem mnuCaffeine    = new System.Windows.Forms.MenuItem("Caffeine", new EventHandler(this.CaffeineMenuEventHandler));
            mnuAutostart         = new System.Windows.Forms.MenuItem("Autostart", new EventHandler(this.AutostartMenuEventHandler));
            mnuAutostart.Checked = Autostart.CheckStartupFolderShortcutsExists();

            System.Windows.Forms.MenuItem mnuExit = new System.Windows.Forms.MenuItem("Close", new EventHandler(this.ExitMenuEventHandler));
            mnuLabel         = new System.Windows.Forms.MenuItem("");
            mnuLabel.Enabled = false; // greyed-out style label

            System.Windows.Forms.MenuItem[] menuitems = new System.Windows.Forms.MenuItem[]
            {
                mnuLabel, new System.Windows.Forms.MenuItem("-"), mnuMonitorOff, mnuScreenSaver, mnuSleep, new System.Windows.Forms.MenuItem("-"), mnuCaffeine, new System.Windows.Forms.MenuItem("-"), mnuAutostart, new System.Windows.Forms.MenuItem("-"), mnuExit
            };

            System.Windows.Forms.ContextMenu contextmenu = new System.Windows.Forms.ContextMenu(menuitems);
            contextmenu.Popup += this.ContextMenuPopup;

            notifyicon.ContextMenu = contextmenu;

            notifyicon.MouseClick       += this.NotifyIconClick;
            notifyicon.MouseDoubleClick += this.NotifyIconClick;

            notifyicon.Visible = true;

            DrawIcon.updateNotifyIcon(notifyicon, currentBrightness);

            this.NotifyIcon = notifyicon;
        }
 private void RegistryWatcher_OnUpdateStatus(object sender, string e)
 {
     DrawIcon.updateNotifyIcon(NotifyIcon, WmiFunctions.GetBrightnessLevel());
 }