views:

3336

answers:

5

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
+1  A: 

Check FlatStyle property. Setting it to "System" makes the checkbox sunken in my environment.

Stanislav Kniazev
That makes it flat when the box is unchecked however.
Jason Down
It's raised when unchecked and sunken when checked on my machine (Vista made to look like Win 2000 - Windows Classic theme).
Stanislav Kniazev
You're right! I accidentally had it on Popup for the style. My bad.
Jason Down
If the buttons are to be mutually exclusive, you could do the same thing with RadioButton, also.
Ken
+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
+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
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