I have a weird problem (probably only to understand) why in a test app the focus rect is not shown until i press the tab key.
I want to show a dialog with two radioboxes and two buttons. When i display the dialog, i'd like to see a focus rect around my first radiobutton. (So that the user can see where the focus is.) I ordered the controls and set the tabindex property from 0 to 4 so that they are in the correct order. (radiobox 1 has tabindex 0, ...)
When i show the dialog the first radiobox has the focus, but it has no focus rect around it. (Until i press tab key.)
I created an completely empty winforms project (Visual Studio 2010), added the controls and started it. So there is nothing special at all.
Can someone give me a hint what i am doing wrong?
Sorry, here is the code of my sample:
Public Class Form1
Private Sub Button1_Click(sender As System.Object, _
e As System.EventArgs) _
Handles Button1.Click
Me.Close()
End Sub
Private Sub Button2_Click(sender As System.Object, _
e As System.EventArgs) _
Handles Button2.Click
Me.Close()
End Sub
Private Sub Form1_Shown(sender As Object, _
e As System.EventArgs) _
Handles Me.Shown
RadioButton1.Focus()
RadioButton1.Select()
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("+{TAB}")
End Sub
End Class
As I commented, this is really a user preference setting.
But to show the rectangle, try inheriting your own RadioButton and override the ShowFocusCues
function:
Public Class RadioWithFocus
Inherits RadioButton
Protected Overrides ReadOnly Property ShowFocusCues() As Boolean
Get
Return True
End Get
End Property
End Class
Use the inherited Control.Focus()
in the initialization method of your form, or wherever applicable. Something like:
public Form1 () {
//Other stuff here
radiobox1.Focus();// If this is the name of your control
}
Another method to look at is Form.Activate
. This is probably better to use in this context
Also, ActiveControl
might be helpful.
For Win32/C++, send the WM_CHANGEUISTATE message to the parent window:
// Enable focus rect and accelerator underline in all controls.
::SendMessage(WM_CHANGEUISTATE, MAKELONG(UIS_CLEAR, UISF_HIDEACCEL | UISF_HIDEFOCUS), 0);
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