Make only the box clickable on a CheckBox

  • Thread starter Thread starter aaron.jackson
  • Start date Start date
A

aaron.jackson

I need to restrict ability to check/uncheck a
System.Windows.Forms.CheckBox to only the actual box and not the label
that is displayed next to the CheckBox. Any ideas?
 
I don't know of any attribute that you can set to get the effect you
want. I can however think of a couple of ways you could hack this
functionality together if you wish.

You could either override the click event for the control, and if the
(x,y) coordinates of the mouse during click are not in the rectangle
you want you can ignore the click, or you could extend the CheckBox
class and create your own CheckBox that has a transparent panel over
everything but the actual check box. This transparent panel would then
capture all of the clicks made in the text area.

Sorry if these are not elegant enough. I'm not saying you should give
up looking for a better solution, but if you do give those hacks a
shot. Good luck!
 
You can simply set the checkbox's text to "", and resize its width so that
only the box is seen. Then you place a label besides the checkbox as its
label.
 
I need to restrict ability to check/uncheck a
System.Windows.Forms.CheckBox to only the actual box and not the label
that is displayed next to the CheckBox. Any ideas?


I am wondering why you would like to archieve such an unintuitive
behavior...
 
It would not be the academically accepted behavior for a TextBox (and
might really hurt your less mouseically skilled users), but after
working with many UI designers you find amazing new reasons why you
might have to hack a Windows Forms control to do something "weird" that
really enhances usability.
 
I agree that the behavior is out of the norm. The interface for this
form repeats a controls that has many checkboxes on each control. We
have found that people are accidentally checking items that they don't
intend to because the real estate covered by the numerous checkboxes is
fairly large.
 
Back
Top