Windows Develop Bookmark and Share   
 index > Windows Forms General > Crazy checkbox issue
 

Crazy checkbox issue

I have a windows form with a panel that contains a checkbox with the tab index set to zero. When the form loads the checkbox has the focus, but the outline of the checkbox text is not there until you tab away from the first checkbox then back.

Any ideas?

shill1  Tuesday, September 11, 2007 7:44 PM

I found the fix that works consistently. Put the code in the paint event of the panel control.

shill1  Thursday, September 13, 2007 1:31 PM

I'm not sure what you mean but you must be aware that the TabIndex property of the checkbox corresponds to the panel

not to the form. You can have the TabIndex of the Panel set to zero and the checkbox tabindex set to zero to have it outlined as the form is first shown. What is probably happening is that another control is getting the focus before the panel. Check your panel tabindex.

Fábio Franco  Tuesday, September 11, 2007 8:19 PM

It still does not work. You too can reproduce the problem. Create a new windows forms application. On the blank form drag and drop 2 checkbox controls. Set the tab index to 0 and 1 respectively. Run the application. The first checkbox control with tab index of zero is not outlined, even though it has the focus. Hit tab, this will outline the second checkbox. Now hit the up arrow, this will outline the first checkbox.

I need the first checkbox to be outlined when the form loads.

shill1  Tuesday, September 11, 2007 8:24 PM

Holy ***, You just found a .Net Framework bug! Now, to who you should report this I don't know, but to get it working it is simple, just write this code:

chkBox2.Focus();

chkBox1.Focus();

Fábio Franco  Tuesday, September 11, 2007 8:39 PM

I tried that in the form load event, to no avail. I am using VB, not C# though. What event are you placing the code?

shill1  Tuesday, September 11, 2007 8:42 PM

Actually the code above wont do the trick, Im trying to figure out how to do it, but probably I'll have to send keyboard input

to get it outlined

Fábio Franco  Tuesday, September 11, 2007 8:43 PM

I have a fix that works. Thanks.

In the form load add:

SendKeys.Send("{TAB}")

SendKeys.Send("+{TAB}")

shill1  Tuesday, September 11, 2007 8:47 PM

That is what I was going to post now. Good, butit is really weird that nobody noticed this before.

Fábio Franco  Tuesday, September 11, 2007 8:51 PM

Actually this is not even working consistently. Please let me know if you find a different solution. Thank you.

shill1  Wednesday, September 12, 2007 3:30 PM

Yeah I noticed that. Put that code on the Form.Shown event. It seems to work nicely

Fábio Franco  Wednesday, September 12, 2007 5:39 PM

I found the fix that works consistently. Put the code in the paint event of the panel control.

shill1  Thursday, September 13, 2007 1:31 PM

You can use google to search for other answers

Custom Search

More Threads

• How to working with two SqlDataReader
• Custom Control and Windows 2000 domain
• Disposing a form which has user control?
• Hyperlinks in Executable Files
• clipped text from autoellipsis on label
• validation
• Find the line control
• Reading in XML
• ExtenderProvider's properties
• The process cannot access the file because it is being used by another process