tags:

views:

177

answers:

3

I have a checkbox with no text specified. Now whenever I tab down to this checkbox, it doesnot get highlighted.I even tried setting focus in checkbox_Enter() event. I checked for focus in this event and focus is there in this checkbox. How to get it highlighted so that user can know that the cursor is there in checkbox.

A: 
  • Try putting just a space into the Checkbox

Or

  • setting AutoSize to false
  • Setting the size of the Checkbox

Then there may be somewhere for WinForms to draw the focus ret.

Otherwise you have to to custom draw the Checkbox, or draw the focus rec round the Checkbox yourself.


Whatever you do it will not look that good, as users expect the focus rec to be round the label of the checkbox, and you wish to have a checkbox with no label.

Ian Ringrose
how to put space in checkbox.U mean to say,in checkbox_Enter() event.
Rohit
no set the "Text" prop to contain a space.
Ian Ringrose
Can u please tell me how to draw focus rectangle.I am using ControlPaint.DrawFocusRectangle(Graphics,Rectangle).How to get the graphics in checkbox_Enter() event.According to my knowledge it is available in OnPaint event.
Rohit
A: 

Actually the highlights comes on the text of the checkbox not the checkbox itself

So, if I was you, I would put any control in the background of my check box and give it the focus when my checkbox is focused, to have the same look of default controls highlights.

which will be shown to end users as checkbox highlights.

amr osama
Please tell how to do that.
Rohit
-1 as giving the focus to another control will stop the space bar changing the value of the checkbox.
Ian Ringrose
here is the way, put button little bit bigger than your checkbox behind the checkbox.then make his flatStyle property to flatand foreColor property to same color of your form background.then on the click event of the button write this code checkBox1.Checked = !checkBox1.Checked;*this solve the bug which "lan Ringrose" mentioned.that's it
amr osama
A: 

I managed to do it by the below mentioned way

Use a panel.Push the checkbox inside that panel.Set the dimensions of a panel as such that it looks like a rectangle around the checkbox.In checkbox_enter() event set the border

BorderStyle.FixedSingle;

And in checkbox_Leave() event set the border again to

BorderStyle.None;

So this way it will tell user that focus in inside the checkbox.

Rohit