Is it possible to create a toggle button in C# WinForms? I know that you can use a CheckBox control and set it's Appearance property to "Button", but it doesn't look right. I want it to appear sunken, not flat, when pressed. Any thoughts?
A:
You can always code your own button with custom graphics and a PictureBox, though it won't necessarily match the Windows theme of your users.
HanClinto
2008-11-11 21:02:24
+1
A:
Check FlatStyle property. Setting it to "System" makes the checkbox sunken in my environment.
Stanislav Kniazev
2008-11-11 21:10:14
That makes it flat when the box is unchecked however.
Jason Down
2008-11-11 21:12:09
It's raised when unchecked and sunken when checked on my machine (Vista made to look like Win 2000 - Windows Classic theme).
Stanislav Kniazev
2008-11-11 21:15:18
You're right! I accidentally had it on Popup for the style. My bad.
Jason Down
2008-11-11 21:17:53
If the buttons are to be mutually exclusive, you could do the same thing with RadioButton, also.
Ken
2010-04-19 14:06:25
+1
A:
You may also consider the ToolStripButton control if you don't mind hosting it in a ToolStripContainer. I think it can natively support pressed and unpressed states.
C. Dragon 76
2008-11-11 21:14:01
+1
A:
I ended up overriding the OnPaint and OnBackgroundPaint events and manually drawing the button exactly like I need it. It worked pretty well.
Jon Tackabury
2009-01-06 13:36:34
A:
You can just use a checkbox and set its apearance to Button
Thanks to http://www.osix.net/modules/article/?id=797 for pointing this out
Simon Sabin
2010-09-23 09:21:57