Skip LinkLabel in TAB order

G

Guest

I have designed a custom control derived from UserControl which contains a
LinkLabel and a TextBox. If the user uses the TAB key to move the focus to my
custom control I want the TextBox to get the focus and not the LinkLabel.
Therefore I set the TabStop property of the LinkLabel control to False (in
the constructor of my custom control, after InitializeComponent()). However,
the TabStop property of the LinkLabel is ignored and it still gets the focus.
As a workaround I tried to override OnEnter of my custom control:

Protected Overrides Sub OnEnter(ByVal e As System.EventArgs)
myTextBox.Focus()
End Sub

Unfortunately this doesn't work either. The TextBox gets the focus but
immediately afterwards the focus moves to the LinkLabel. Overriding
OnGotfocus results in the same behaviour.
How could I prevent the LinkLabel to get the focus if the user uses the TAB
key to move the focus to my custom control?

Thanks for any ideas,
Guido
 
H

Herfried K. Wagner [MVP]

Guido Kraus said:
I have designed a custom control derived from UserControl which contains a
LinkLabel and a TextBox. If the user uses the TAB key to move the focus to
my
custom control I want the TextBox to get the focus and not the LinkLabel.
Therefore I set the TabStop property of the LinkLabel control to False (in
the constructor of my custom control, after InitializeComponent()).
However,
the TabStop property of the LinkLabel is ignored and it still gets the
focus.

I am not able to reproduce this behavior with .NET 1.1/Windows XP
Professional SP2.
 
G

Guest

You are right. I was fooled by the TabStop property of the LinkLabel which is
automatically set to True if you change the Text property of the LinkLabel.
My custom control exposes a LinkText property which sets the text of the
LinkLabel. Therefore the container of my custom control silently activated
the TabStop property by setting the text of the LinkLabel. So the simple
solution to the problem is:

Public Property LinkText() As String
Get
Return lnkLink.Text
End Get
Set(ByVal Value As String)
lnkLink.Text = Value
lnkLink.TabStop = False
End Set
End Property
 
K

Kevin Yu [MSFT]

Hi Guido,

It was nice hear that you have had the problem resolved. Thanks for sharing
your experience with all the people here. If you have any questions, please
feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top