views:

248

answers:

4

Hi, I have a list box with Checkboxes in it. I want to prevent the Checkbox from changing its status if the user clicks on the text next to it. I only want it to change if the small box is clicked directly.

Is there any way to do this in windows forms?

Greetings and thanks in advance.

A: 

You could always not fill in the Text property of the Checkbox and make a completely separate Label control.
Otherwise, you will probably have to do explicit hit testing within the control to see if they hit the box or text. And then you will have to worry about checking the margins, which side the box is on, and other things that can change the position of the box.

toast
+6  A: 

Place the text next to it in a Label, instead of the Text property of the Checkbox. Or you could create your own control which has a Checkbox and a Label. The Text property of the control would then fill the Text in the Label, and you could expose all of the Checkboxes regular properties in your control.

Yuriy Faktorovich
+1. Thats exactly what I was going to suggest.
David Stratton
Ok thank you, seems that there is no way around to create my own control
lakai
+2  A: 

That's fairly non-standard behavior. Users are going to expect to be able to change the checkbox when clicking on its label, and are going to be frustrated, confused, and surprised when it doesn't work. I'd recommend not doing this. I'm not the only one.

(Yes, it's about web design, but many of the concepts are applicable in desktop application design as well.)

Matt Ball
Sounds more like a comment.
Yuriy Faktorovich
Fair enough. However, I think it's important enough to not surprise your users to warrant putting it in an answer instead.
Matt Ball
A: 

I personally was only able to freeze things. I freeze the check boxes by handling the Click and ItemChecked events, and change the check state back, when it gets modified. I use a menu to check/uncheck items and let user decide to use the menu or classic behave.

Cheers, good luck.

FAV