Reputation: 209
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.
Upvotes: 0
Views: 1166
Reputation: 1
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.
Upvotes: 0
Reputation: 359826
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.)
Upvotes: 2
Reputation: 68687
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.
Upvotes: 6
Reputation: 4171
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.
Upvotes: 0