views:

43

answers:

2

How can I add the the sleek On/Off control to a Windows Forms application?

Or do I need to use WPF?

Example

Ignore the red highlighted area, look at the on/off controls (screenshot lifted from Visual Studio Power Productivity Tools).

alt text

+3  A: 

In a WinForms app, you can easily create your own custom UserControl to do this (and I'm sure someone's written something like this and posted it somewhere). It's nothing more than giving a 3D recessed border to the control, and adding two labels (ON and OFF) and a disabled button and adding the code to move the button left or right on a click event. You'd want to give the control the same interface as a CheckBox (i.e. with a "Checked" property).

Incidentally, I know this control is in the style of the iPhone, which makes it supposedly "cool", but from my perspective the main achievement here is that it takes up a lot more space than a checkbox, and fundamentally ties the control to English (unless you put in the extra work to replace "ON" and "OFF" with whatever else is needed for a particular language).

This control actually makes some sense on a phone, since it's easier to manipulate with the thumb than a checkbox is. I don't think it's very valuable to have it in a Windows application (the Visual Studio designers obviously think otherwise).

MusiGenesis
+1 for naming the "main acchievement"
phimuemue
Thanks, I realise this is just a glorified checkbox, but using a checkbox in my instance would require clarifying that the checkbox is to turn my modules on or off (and not a select list of some kind) and this just looks nice. I'll probably just stick with a checkbox :).
FreshCode
@FreshCode: well, now I feel guilty. One advantage of the slider over a checkbox is that you can give meaningful labels to the on/off states, as you point out. This really would be an easy thing to do as a UserControl, and you'd get the added experience of cobbling one together.
MusiGenesis
+1  A: 

Devcomponents has a commercial control that you could use.

http://www.devcomponents.com/dotnetbar/SwitchButtonControl.aspx

geoff
+1 the tool you link to seems (albeit commercial) to do this exact job. i have to admit i haven't tried it myself
hawbsl