CheckBox Control Acts as Toggle Button

2016-07-11


We needed to use common Windows Forms control to show a simple toggle style small text box. We firstly wanted to use Textbox control, but later we found Textbox control is not good for toggling.

Then we found we can use Checkbox control, Checkbox provides a feature named Appearance, we can set its Appearance as a button:

Like the following code:

CheckBox toggleBtn = new CheckBox();
toggleBtn .Appearance = Appearance.Button;
toggleBtn .TextAlign = ContentAlignment.MiddleCenter;
toggleBtn .MinimumSize = new Size(25, 25); //set mini size

It worked great!