views:

250

answers:

2

Hi, All

I have a multiple checkboxes on a Winforms without having the Text Property of all checkboxes, so the problem is that when i hover a mouse on the checkbox it highlighted but when i go to the checkbox using tab key it never get highlighted..

If anyone have the similar issue and already solved it Please help..

A: 

The problem is that when a check box gets focus it highlights only the text portion of the control which is empty in your case. You have a few choices:

1) For all your "blank" text boxes, set the text property to a space. This will create a small highlighted portion when you tab to the control.

2) Program the OnEnter and OnLeave events of the checkbox, and draw/paint a square around the whole control.

3) If you want the default MouseEnter behaviour which creates a yellowish highlight on the check box itself, create your own check box control as follows:

public class MyCB : CheckBox
{
    protected override void OnEnter(EventArgs e)
    {
      base.OnEnter(e);
      base.OnMouseEnter(e);
    }

    protected override void OnLeave(EventArgs e)
    {
      base.OnLeave(e);
      base.OnMouseLeave(e);
    }
}
AKoran
A: 

You can fix this by setting the AutoSize property = False. When AutoSize is True, it acts like a Label with AutoSize set to true, in that an empty label will take up almost no space on the screen. With AutoSize = False, you can manually set the bounding rectangle for the checkbox.

Nick
Setting the AutoSize property to false still doesn't change the fact that the text is empty and by default when you tab into a checkbox it only highlights the text block, not the entire control itself. You can make the control as big as you want, AutoSize applies to the CheckBox, not the TextBox inside the CheckBox.
AKoran