using System.Linq; namespace RobvanderWoude { public partial class ScrollLockIcon : System.Windows.Forms.Form { static string progver = "1.00"; static string copyrightsyear = "2021"; #region Global Variables private System.Windows.Forms.NotifyIcon scrolllockicon; private System.Windows.Forms.ContextMenu contextmenu; private System.Windows.Forms.MenuItem menuitemexit; private System.Windows.Forms.MenuItem menuitemsettings; private System.Windows.Forms.Form formsettings; private System.Windows.Forms.TextBox textbox; private System.Windows.Forms.ComboBox dropdowncoloroff; private System.Windows.Forms.ComboBox dropdowncoloron; private System.Windows.Forms.CheckBox checkboxflashwhenoff; private System.Windows.Forms.CheckBox checkboxflashwhenon; private System.Windows.Forms.CheckBox checkboxhidewhenoff; private System.Collections.Generic.List iconsoff; private System.Collections.Generic.List iconson; private System.Windows.Forms.Timer timer; private readonly System.Drawing.Brush black = System.Drawing.Brushes.Black; private bool scrolllock; #endregion Global Variables /// /// The main entry point for the application. /// [System.STAThread] static void Main( ) { System.Windows.Forms.Application.EnableVisualStyles( ); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault( false ); System.Windows.Forms.Application.Run( new ScrollLockIcon( ) ); } public ScrollLockIcon( ) { ReadSettings( ); scrolllockicon = new System.Windows.Forms.NotifyIcon( ); // Determine which icon should be displayed iconsoff = new System.Collections.Generic.List( ) { CreateIcon( GlobalSettings.IndicatorText, black, GlobalSettings.IndicatorColorOFF ), CreateIcon( GlobalSettings.IndicatorText, GlobalSettings.IndicatorColorOFF, black ) }; iconson = new System.Collections.Generic.List( ) { CreateIcon( GlobalSettings.IndicatorText, black, GlobalSettings.IndicatorColorON ), CreateIcon( GlobalSettings.IndicatorText, GlobalSettings.IndicatorColorON, black ) }; scrolllock = System.Windows.Forms.Control.IsKeyLocked( System.Windows.Forms.Keys.Scroll ); this.scrolllockicon.Icon = iconson[0]; // Context Menu this.contextmenu = new System.Windows.Forms.ContextMenu( ); // Context Menu: Settings this.menuitemsettings = new System.Windows.Forms.MenuItem( "&Settings", new System.EventHandler( MenuItemSettings_Click ) ); this.contextmenu.MenuItems.Add( menuitemsettings ); // Context Menu: Exit this.menuitemexit = new System.Windows.Forms.MenuItem( "E&xit", new System.EventHandler( MenuItemExit_Click ) ); this.contextmenu.MenuItems.Add( menuitemexit ); this.scrolllockicon.ContextMenu = this.contextmenu; this.scrolllockicon.Visible = true; // Timer for key monitoring interval this.timer = new System.Windows.Forms.Timer( ); this.timer.Interval = 1000; this.timer.Tick += new System.EventHandler( Timer_Tick ); this.timer.Start( ); // Store version information in the registry if ( ReadRegValue( "Version", string.Empty ) != progver ) { WriteRegValue( "Version", progver ); WriteRegValue( "URL", "https://www.robvanderwoude.com/csharpexamples.php#ScrollLockIcon" ); WriteRegValue( "Requirement", RequiredNetVersion( ) ); } } /// /// Code to dynamically generate icons by Joshua Flanagan on CodeProject.com /// https://www.codeproject.com/Articles/7122/Dynamically-Generating-Icons-safely /// public System.Drawing.Icon CreateIcon( string text, System.Drawing.Brush fgcolor, System.Drawing.Brush bgcolor ) { System.Drawing.Icon icon = null; System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap( 16, 16 ); System.Drawing.Font font = new System.Drawing.Font( System.Drawing.FontFamily.GenericSansSerif, 8F, System.Drawing.FontStyle.Bold ); using ( System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage( bitmap ) ) { graphic.FillEllipse( bgcolor, 0, 0, 16, 16 ); System.Drawing.SizeF textsize = graphic.MeasureString( text, font ); System.Single x = System.Convert.ToSingle( System.Math.Floor( ( bitmap.Width - textsize.Width ) / 2 ) ); System.Single y = System.Convert.ToSingle( System.Math.Ceiling( ( bitmap.Height - textsize.Height ) / 2 ) ); graphic.DrawString( text, font, fgcolor, x, y, System.Drawing.StringFormat.GenericDefault ); icon = System.Drawing.Icon.FromHandle( bitmap.GetHicon( ) ); } return icon; } public System.Drawing.Size GetTextSize( string text ) { return System.Windows.Forms.TextRenderer.MeasureText( text, formsettings.Font ); } public void OpenURL( string url ) { System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo( url ); System.Diagnostics.Process.Start( startinfo ); } public void Quit( ) { this.timer.Stop( ); this.timer.Dispose( ); this.scrolllockicon.Visible = false; this.scrolllockicon.Dispose( ); System.Windows.Forms.Application.Exit( ); } public void ReadSettings( ) { GlobalSettings.FlashIfOFF = ReadRegValue( "FlashIfOFF", GlobalSettings.FlashIfOFF ); GlobalSettings.FlashIfON = ReadRegValue( "FlashIfON", GlobalSettings.FlashIfON ); GlobalSettings.HideIfOFF = ReadRegValue( "HideIfOFF", GlobalSettings.HideIfOFF ); string currentcolor = GlobalSettings.Colors.Where( c => c.Value.Equals( GlobalSettings.IndicatorColorOFF ) ).First( ).Key; // requires System.Linq GlobalSettings.IndicatorColorOFF = GlobalSettings.Colors[ReadRegValue( "IndicatorColorOFF", currentcolor )]; currentcolor = GlobalSettings.Colors.Where( c => c.Value.Equals( GlobalSettings.IndicatorColorON ) ).First( ).Key; // requires System.Linq GlobalSettings.IndicatorColorON = GlobalSettings.Colors[ReadRegValue( "IndicatorColorON", currentcolor )]; GlobalSettings.IndicatorText = ReadRegValue( "IndicatorText", GlobalSettings.IndicatorText ); } /// /// Code to get the required .NET Framework version by Fernando Gonzalez Sanchez on StackOverflow.com /// https://stackoverflow.com/a/18623516 /// static string RequiredNetVersion( ) { object[] list = System.Reflection.Assembly.GetExecutingAssembly( ).GetCustomAttributes( true ); var attribute = list.OfType( ).First( ); // requires Linq string frameworkname = attribute.FrameworkName; string frameworkdisplayname = attribute.FrameworkDisplayName; return frameworkdisplayname; } public void SaveSettings( ) { // Adjust global settings GlobalSettings.FlashIfOFF = checkboxflashwhenoff.Checked && !checkboxhidewhenoff.Checked; GlobalSettings.FlashIfON = checkboxflashwhenon.Checked; GlobalSettings.HideIfOFF = checkboxhidewhenoff.Checked; GlobalSettings.IndicatorColorOFF = GlobalSettings.Colors[dropdowncoloroff.Text]; GlobalSettings.IndicatorColorON = GlobalSettings.Colors[dropdowncoloron.Text]; if ( !string.IsNullOrWhiteSpace( textbox.Text ) ) { GlobalSettings.IndicatorText = textbox.Text.Trim( ); } // Update program status iconsoff = new System.Collections.Generic.List( ) { CreateIcon( GlobalSettings.IndicatorText, black, GlobalSettings.IndicatorColorOFF ), CreateIcon( GlobalSettings.IndicatorText, GlobalSettings.IndicatorColorOFF, black ) }; iconson = new System.Collections.Generic.List( ) { CreateIcon( GlobalSettings.IndicatorText, black, GlobalSettings.IndicatorColorON ), CreateIcon( GlobalSettings.IndicatorText, GlobalSettings.IndicatorColorON, black ) }; // Save settings to registry bool success = true; success = success && WriteRegValue( "FlashIfOFF", GlobalSettings.FlashIfOFF ); success = success && WriteRegValue( "FlashIfON", GlobalSettings.FlashIfON ); success = success && WriteRegValue( "HideIfOFF", GlobalSettings.HideIfOFF ); success = success && WriteRegValue( "IndicatorColorOFF", GlobalSettings.Colors.Where( c => c.Value.Equals( GlobalSettings.IndicatorColorOFF ) ).First( ).Key ); success = success && WriteRegValue( "IndicatorColorON", GlobalSettings.Colors.Where( c => c.Value.Equals( GlobalSettings.IndicatorColorON ) ).First( ).Key ); success = success && WriteRegValue( "IndicatorText", GlobalSettings.IndicatorText ); if ( success ) { System.Windows.Forms.MessageBox.Show( "Settings were successfully stored in the registry", "Settings Saved", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information ); } else { System.Windows.Forms.MessageBox.Show( "Unable to store the settings in the registry", "Error Saving Settings", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error ); } // Close settings window formsettings.Close( ); } public void Settings( ) { ReadSettings( ); System.Int32 column1width = 0; System.Int32 column2width = 0; System.Int32 rowheight = 30; formsettings = new System.Windows.Forms.Form( ); formsettings.Text = string.Format( "ScrollLockIcon {0} Settings \u00A9 {1} Rob van der Woude", progver, copyrightsyear ); formsettings.Size = new System.Drawing.Size( 500, 425 ); formsettings.Font = new System.Drawing.Font( System.Drawing.FontFamily.GenericSansSerif, 10F ); // Column 1 Row 1 System.Windows.Forms.Label labeltext = new System.Windows.Forms.Label( ); labeltext.Text = "Indicator text"; column1width = System.Math.Max( column1width, GetTextSize( labeltext.Text ).Width ); labeltext.Location = new System.Drawing.Point( 20, 20 ); formsettings.Controls.Add( labeltext ); // Column 1 Row 2 System.Windows.Forms.Label labelcoloroff = new System.Windows.Forms.Label( ); labelcoloroff.Text = "Indicator color when OFF"; labelcoloroff.AutoSize = true; column1width = System.Math.Max( column1width, GetTextSize( labelcoloroff.Text ).Width ); labelcoloroff.Location = new System.Drawing.Point( labeltext.Location.X, labeltext.Location.Y + labeltext.Height + rowheight ); formsettings.Controls.Add( labelcoloroff ); // Column 1 Row 3 System.Windows.Forms.Label labelcoloron = new System.Windows.Forms.Label( ); labelcoloron.Text = "Indicator color when ON"; labelcoloron.AutoSize = true; column1width = System.Math.Max( column1width, GetTextSize( labelcoloron.Text ).Width ); labelcoloron.Location = new System.Drawing.Point( labelcoloroff.Location.X, labelcoloroff.Location.Y + labelcoloroff.Height + rowheight ); formsettings.Controls.Add( labelcoloron ); // Column 2 Row 1 textbox = new System.Windows.Forms.TextBox( ); textbox.Text = GlobalSettings.IndicatorText; textbox.MaxLength = 2; textbox.SelectionStart = textbox.Text.Length; textbox.SelectionLength = 0; column2width = System.Math.Max( column2width, textbox.Width ); textbox.Location = new System.Drawing.Point( column1width + 30, labeltext.Location.Y ); formsettings.Controls.Add( textbox ); // Column 2 Row 2 dropdowncoloroff = new System.Windows.Forms.ComboBox( ); ComboboxItem item; foreach ( string color in GlobalSettings.Colors.Keys ) { item = new ComboboxItem( ); item.Text = color; item.Value = GlobalSettings.Colors[color]; dropdowncoloroff.Items.Add( item ); } dropdowncoloroff.SelectedIndex = GlobalSettings.Colors.Values.ToList( ).IndexOf( GlobalSettings.IndicatorColorOFF ); // requires System.Linq column2width = System.Math.Max( column2width, dropdowncoloroff.Width ); dropdowncoloroff.Enabled = !GlobalSettings.HideIfOFF; dropdowncoloroff.Location = new System.Drawing.Point( column1width + 30, labelcoloroff.Location.Y ); formsettings.Controls.Add( dropdowncoloroff ); // Column 2 Row 3 dropdowncoloron = new System.Windows.Forms.ComboBox( ); foreach ( string color in GlobalSettings.Colors.Keys ) { item = new ComboboxItem( ); item.Text = color; item.Value = GlobalSettings.Colors[color]; dropdowncoloron.Items.Add( item ); } dropdowncoloron.SelectedIndex = GlobalSettings.Colors.Values.ToList( ).IndexOf( GlobalSettings.IndicatorColorON ); // requires System.Linq column2width = System.Math.Max( column2width, dropdowncoloron.Width ); dropdowncoloron.Location = new System.Drawing.Point( column1width + 30, labelcoloron.Location.Y ); formsettings.Controls.Add( dropdowncoloron ); // Column 3 Row 1 checkboxhidewhenoff = new System.Windows.Forms.CheckBox( ); checkboxhidewhenoff.Text = " Hide when OFF"; checkboxhidewhenoff.AutoSize = true; checkboxhidewhenoff.Checked = GlobalSettings.HideIfOFF; checkboxhidewhenoff.Location = new System.Drawing.Point( column1width + column2width + 50, textbox.Location.Y ); checkboxhidewhenoff.Click += Checkboxhidewhenoff_Click; checkboxhidewhenoff.KeyPress += Checkboxhidewhenoff_KeyPress; formsettings.Controls.Add( checkboxhidewhenoff ); // Column 3 Row 2 checkboxflashwhenoff = new System.Windows.Forms.CheckBox( ); checkboxflashwhenoff.Text = " Flash when OFF"; checkboxflashwhenoff.AutoSize = true; checkboxflashwhenoff.Checked = GlobalSettings.FlashIfOFF && !GlobalSettings.HideIfOFF; checkboxflashwhenoff.Enabled = !GlobalSettings.HideIfOFF; checkboxflashwhenoff.Location = new System.Drawing.Point( column1width + column2width + 50, dropdowncoloroff.Location.Y ); formsettings.Controls.Add( checkboxflashwhenoff ); // Column 3 Row 3 checkboxflashwhenon = new System.Windows.Forms.CheckBox( ); checkboxflashwhenon.Text = " Flash when ON"; checkboxflashwhenon.AutoSize = true; checkboxflashwhenon.Checked = GlobalSettings.FlashIfON; checkboxflashwhenon.Location = new System.Drawing.Point( column1width + column2width + 50, dropdowncoloron.Location.Y ); formsettings.Controls.Add( checkboxflashwhenon ); // Buttons System.Windows.Forms.Button buttonsave = new System.Windows.Forms.Button( ); buttonsave.Text = "Save"; buttonsave.Click += new System.EventHandler( ButtonSave_Click ); buttonsave.Size = new System.Drawing.Size( 100, 32 ); buttonsave.Location = new System.Drawing.Point( formsettings.ClientSize.Width / 2 - buttonsave.Width - 20, labelcoloron.Location.Y + 2 * rowheight ); formsettings.Controls.Add( buttonsave ); System.Windows.Forms.Button buttoncancel = new System.Windows.Forms.Button( ); buttoncancel.Text = "Cancel"; buttoncancel.Click += new System.EventHandler( ButtonCancel_Click ); buttoncancel.Size = new System.Drawing.Size( 100, 32 ); buttoncancel.Location = new System.Drawing.Point( formsettings.ClientSize.Width / 2 + 20, buttonsave.Location.Y ); formsettings.Controls.Add( buttoncancel ); // URLs System.Windows.Forms.Label labelurlrvdw = new System.Windows.Forms.Label( ); labelurlrvdw.Text = "Written by Rob van der Woude\nhttps://www.robvanderwoude.com"; labelurlrvdw.Click += new System.EventHandler( LabelUrlRvdw_Click ); labelurlrvdw.AutoSize = true; labelurlrvdw.Location = new System.Drawing.Point( 20, buttonsave.Location.Y + 2 * rowheight ); formsettings.Controls.Add( labelurlrvdw ); System.Windows.Forms.Label labelurljficos = new System.Windows.Forms.Label( ); labelurljficos.Text = "Code to dynamically generate icons by Joshua Flanagan on CodeProject.com\nhttps://www.codeproject.com/Articles/7122/Dynamically-Generating-Icons-safely"; labelurljficos.Font = new System.Drawing.Font( labelurljficos.Font.FontFamily, labelurljficos.Font.Size * 0.9F, labelurljficos.Font.Style ); labelurljficos.Click += new System.EventHandler( LabelUrlJfIcos_Click ); labelurljficos.AutoSize = true; labelurljficos.Location = new System.Drawing.Point( 20, System.Convert.ToInt32( labelurlrvdw.Location.Y + 1.5 * rowheight ) ); formsettings.Controls.Add( labelurljficos ); System.Windows.Forms.Label labelurlchw = new System.Windows.Forms.Label( ); labelurlchw.Text = "Code to hide main form by Chriz on StackOverflow.com\nhttps://stackoverflow.com/a/11831856"; labelurlchw.Font = new System.Drawing.Font( labelurlchw.Font.FontFamily, labelurlchw.Font.Size * 0.9F, labelurlchw.Font.Style ); labelurlchw.Click += new System.EventHandler( LabelUrlChw_Click ); labelurlchw.AutoSize = true; labelurlchw.Location = new System.Drawing.Point( 20, System.Convert.ToInt32( labelurljficos.Location.Y + 1.1 * rowheight ) ); formsettings.Controls.Add( labelurlchw ); System.Windows.Forms.Label labelurlfgs = new System.Windows.Forms.Label( ); labelurlfgs.Text = "Code to get the required .NET Framework version by Fernando Gonzalez Sanchez\nhttps://stackoverflow.com/a/18623516"; labelurlfgs.Font = new System.Drawing.Font( labelurlfgs.Font.FontFamily, labelurlfgs.Font.Size * 0.9F, labelurlfgs.Font.Style ); labelurlfgs.Click += new System.EventHandler( LabelUrlFgs_Click ); labelurlfgs.AutoSize = true; labelurlfgs.Location = new System.Drawing.Point( 20, System.Convert.ToInt32( labelurlchw.Location.Y + 1.1 * rowheight ) ); formsettings.Controls.Add( labelurlfgs ); formsettings.Show( ); } public void UpdateSettingsUI( ) { dropdowncoloroff.Enabled = !checkboxhidewhenoff.Checked; checkboxflashwhenoff.Enabled = !checkboxhidewhenoff.Checked; checkboxflashwhenoff.Checked = checkboxflashwhenoff.Checked && !checkboxhidewhenoff.Checked; } #region Registry static bool ReadRegValue( string name, bool current ) { bool value = false; Microsoft.Win32.RegistryKey regkey = null; try { regkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey( "SOFTWARE\\RobvanderWoude\\ScrollLockIcon", Microsoft.Win32.RegistryKeyPermissionCheck.ReadSubTree ); value = ( regkey.GetValue( name, ( current ? 1 : 0 ) ).ToString( ) == "1" ); regkey.Close( ); return value; } catch ( System.Exception ) { if ( regkey != null ) { regkey.Close( ); } return false; } } static string ReadRegValue( string name, string current ) { string value = current; Microsoft.Win32.RegistryKey regkey = null; try { regkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey( "SOFTWARE\\RobvanderWoude\\ScrollLockIcon", Microsoft.Win32.RegistryKeyPermissionCheck.ReadSubTree ); value = regkey.GetValue( name, current ).ToString( ); regkey.Close( ); } catch ( System.Exception ) { if ( regkey != null ) { regkey.Close( ); } } return value; } static bool WriteRegValue( string name, bool value ) { Microsoft.Win32.RegistryKey regkey = null; try { regkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey( "SOFTWARE\\RobvanderWoude\\ScrollLockIcon", Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree ); regkey.SetValue( name, ( value ? 1 : 0 ), Microsoft.Win32.RegistryValueKind.DWord ); regkey.Close( ); return true; } catch ( System.Exception ) { if ( regkey != null ) { regkey.Close( ); } return false; } } static bool WriteRegValue( string name, string value ) { Microsoft.Win32.RegistryKey regkey = null; try { regkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey( "SOFTWARE\\RobvanderWoude\\ScrollLockIcon", Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree ); regkey.SetValue( name, value, Microsoft.Win32.RegistryValueKind.String ); regkey.Close( ); return true; } catch ( System.Exception ) { if ( regkey != null ) { regkey.Close( ); } return false; } } #endregion Registry #region Event Handlers private void ButtonCancel_Click( object sender, System.EventArgs e ) { formsettings.Close( ); } private void ButtonSave_Click( object sender, System.EventArgs e ) { SaveSettings( ); } private void Checkboxhidewhenoff_KeyPress( object sender, System.Windows.Forms.KeyPressEventArgs e ) { UpdateSettingsUI( ); } private void Checkboxhidewhenoff_Click( object sender, System.EventArgs e ) { UpdateSettingsUI( ); } private void LabelUrlChw_Click( object sender, System.EventArgs e ) { OpenURL( "https://stackoverflow.com/a/11831856" ); } private void LabelUrlFgs_Click( object sender, System.EventArgs e ) { OpenURL( "https://stackoverflow.com/a/18623516" ); } private void LabelUrlJfIcos_Click( object sender, System.EventArgs e ) { OpenURL( "https://www.codeproject.com/Articles/7122/Dynamically-Generating-Icons-safely" ); } private void LabelUrlRvdw_Click( object sender, System.EventArgs e ) { OpenURL( "https://www.robvanderwoude.com/" ); } private void MenuItemExit_Click( System.Object Sender, System.EventArgs e ) { Quit( ); } private void MenuItemSettings_Click( System.Object Sender, System.EventArgs e ) { Settings( ); } private void Timer_Tick( System.Object sender, System.EventArgs e ) { scrolllock = System.Windows.Forms.Control.IsKeyLocked( System.Windows.Forms.Keys.Scroll ); if ( scrolllock ) { this.scrolllockicon.Visible = true; if ( GlobalSettings.FlashIfON ) { if ( this.scrolllockicon.Icon.Equals( iconson[0] ) ) { this.scrolllockicon.Icon = iconson[1]; } else { this.scrolllockicon.Icon = iconson[0]; } } else { this.scrolllockicon.Icon = iconson[0]; } } else { if ( GlobalSettings.HideIfOFF ) { this.scrolllockicon.Visible = false; } else { this.scrolllockicon.Visible = true; if ( GlobalSettings.FlashIfOFF ) { if ( this.scrolllockicon.Icon.Equals( iconsoff[0] ) ) { this.scrolllockicon.Icon = iconsoff[1]; } else { this.scrolllockicon.Icon = iconsoff[0]; } } else { this.scrolllockicon.Icon = iconsoff[0]; } } } } #endregion Event Handlers #region Overrides /// /// Code to hide main form by Chriz on StackOverflow.com /// https://stackoverflow.com/a/11831856 /// protected override void OnLoad( System.EventArgs e ) { Visible = false; // Hide form window. ShowInTaskbar = false; // Remove from taskbar. Opacity = 0; base.OnLoad( e ); } protected override void OnClosed( System.EventArgs e ) { Quit( ); base.OnClosed( e ); } #endregion Overrides public static class GlobalSettings { private static System.Collections.Generic.Dictionary _colors = new System.Collections.Generic.Dictionary( ) { { "LightCyan", System.Drawing.Brushes.LightCyan }, { "LightGreen", System.Drawing.Brushes.LightGreen }, { "Orange", System.Drawing.Brushes.Orange }, { "Red", System.Drawing.Brushes.Red }, { "Yellow", System.Drawing.Brushes.Yellow } }; public static System.Collections.Generic.Dictionary Colors { get { return _colors; } } private static string _indicatortext = "S"; public static string IndicatorText { get { return _indicatortext; } set { _indicatortext = value; } } private static bool _flashifoff = false; public static bool FlashIfOFF { get { return _flashifoff; } set { _flashifoff = value; } } private static bool _flashifon = true; public static bool FlashIfON { get { return _flashifon; } set { _flashifon = value; } } private static bool _hideifoff = false; public static bool HideIfOFF { get { return _hideifoff; } set { _hideifoff = value; } } private static System.Drawing.Brush _indicatorcoloroff = System.Drawing.Brushes.LightGreen; public static System.Drawing.Brush IndicatorColorOFF { get { return _indicatorcoloroff; } set { _indicatorcoloroff = value; } } private static System.Drawing.Brush _indicatorcoloron = System.Drawing.Brushes.Orange; public static System.Drawing.Brush IndicatorColorON { get { return _indicatorcoloron; } set { _indicatorcoloron = value; } } } } public class ComboboxItem { public string Text { get; set; } public System.Object Value { get; set; } public override string ToString( ) { return Text; } } }