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..
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);
}
}
I added an event handler for the CheckBox.Paint
event and added the following:
private void checkBox1_Paint(object sender, PaintEventArgs e)
{
CheckBox checkBox = sender as CheckBox;
if (checkBox.Focused)
{
// e.ClipRectangle is affected by checkBox.Padding. Be careful when changing the Padding.
ControlPaint.DrawFocusRectangle(e.Graphics, e.ClipRectangle, checkBox.ForeColor, checkBox.BackColor);
}
}
I also adjusted the CheckBox.Padding
to be 2, 2, 0, 1
in order to get a border that was 1 pixel from the edge of the CheckBox
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With