Code Repo    |     RSS
MD's Technical Sharing



Sunday, October 26, 2008

Toggle Button in .NET

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#

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;

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.