News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Toggle Button in C#

Started by dhilipkumar, Mar 27, 2009, 03:58 PM

Previous topic - Next topic

dhilipkumar

Toggle Button in C#

Ever wondered how to create a button which toggles it's state in C# windows Forms? It used to exist in VB6 / Office development as a ToggleButton, but cannot easily be found in C#

I was rattling my brains trying to work this out, as the customer specifically said they wanted 'sticky buttons' not checkboxes.

It turns out you need to use the System.Windows.Forms.Checkbox control but set its Appearance property to 'Button'. Usually you would just set this in the IDE but alternatively heres the code ...

CheckBox checkBox1 = new System.Windows.Forms.CheckBox();
checkBox1.Appearance = System.Windows.Forms.Appearance.Button;