CheckBox Control Acts as Toggle Button

Published on Monday, July 11, 2016

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!