Toggle Button in C#

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

Previous topic - Next topic


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;

Quick Reply

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it has been approved by a moderator.

Please leave this box empty:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

Shortcuts: ALT+S post or ALT+P preview