[RESOLVED] Stopping a label from receiving focus
Hi,
I am working on a data entry type form and I want the enter key to move focus to the next text box. I've got that working great except that the focus is moving to the label that is, in sequence, between the text boxes.
In VB6 I didn't have to worry about this because the label couldn't receive focus, in VB.Net it does and I'm not sure how to stop it from receiving focus.
Any ideas?
Re: Stopping a label from receiving focus
Why not use Tab and change the Tab Orders of each Control? Other than that, I have no clue.
Re: Stopping a label from receiving focus
No, the label doesn't recieve focus. VB.NET is better than VB6 in every way!!!!
Are you finding the next control and setting its focus? Can you post your code please?
Re: Stopping a label from receiving focus
Quote:
No, the label doesn't recieve focus. VB.NET is better than VB6 in every way!!!!
Says the guy who won't upgrade from VS 2005 and XP to 2008 and Win7 ;)
Re: Stopping a label from receiving focus
Sure, here is my code:
If e.KeyCode = Windows.Forms.Keys.Enter Then
Dim NextControl As Windows.Forms.Control = GetNextControl(ActiveControl, True)
If Not NextControl Is Nothing Then
NextControl.Focus()
End If
e.SuppressKeyPress = True
e.Handled = True
End If
If I breakpoint the code, after I press enter in the first text box, a label control has focus rather than the next textbox.
Re: Stopping a label from receiving focus
Well, one option may to to check if the 'next' control is a Label, if so move on to the next.
Re: Stopping a label from receiving focus
Why can't you just change the TapStop property of the Label to False? or am I missing the point?
Re: Stopping a label from receiving focus
Just curious, what is your code for moving from one control to another with the enter key.
Re: Stopping a label from receiving focus
weirddemon, I don't believe that a label has a tabstop property, that is part of the issue.
I ended up changing my code and removing it from the form and creating the following routine
Private Sub HandleEnterKey(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtUserID.KeyDown, txtName.KeyDown, txtEmail.KeyDown, txtPassword.KeyDown, txtConfirmPassword.KeyDown
If e.KeyCode = Windows.Forms.Keys.Enter Then
Dim CurrentControl As System.Windows.Forms.Control = CType(sender, System.Windows.Forms.Control)
Me.SelectNextControl(CurrentControl, True, True, True, True)
'Dim NextControl As Windows.Forms.Control = GetNextControl(ActiveControl, True)
'If Not NextControl Is Nothing Then
' NextControl.Focus()
'End If
e.SuppressKeyPress = True
e.Handled = True
End If
End Sub
it works great.
Re: [RESOLVED] Stopping a label from receiving focus
Quote:
weirddemon, I don't believe that a label has a tabstop property, that is part of the issue.
Did you check in code? it's not in the designer, but I was able to set it in code.
Re: [RESOLVED] Stopping a label from receiving focus
I was trying to use this to duplicate the problem but couldn't get it to go to a label. I didn't know you could set the focus to a label?
Code:
'set forms keypreview to true first
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = 13 Then
SendKeys.Send("{TAB}")
End If
End Sub
Re: [RESOLVED] Stopping a label from receiving focus
Quote:
Originally Posted by
weirddemon
Did you check in code? it's not in the designer, but I was able to set it in code.
I was able to set it in code as well but still it wouldn't get the focus when running the program?
Re: [RESOLVED] Stopping a label from receiving focus
Quote:
I was able to set it in code as well but still it wouldn't get the focus when running the program?
Yeah. Same here. I couldn't get the Label to receive the focus. But, I saw the property was available, so I thought to mention it to the OP.
Re: [RESOLVED] Stopping a label from receiving focus
Interesting. If you run this with a form that has a label it tries to set the focus to the label. I couldn't tell if the label actually had the focus or not since it appeared none of the controls had focus?
Code:
Dim NextControl As Windows.Forms.Control = GetNextControl(ActiveControl, True)
If Not NextControl Is Nothing Then
NextControl.Focus()
MsgBox(NextControl.Name)
End If
e.SuppressKeyPress = True
e.Handled = True
Re: Stopping a label from receiving focus
Quote:
Originally Posted by
weirddemon
Says the guy who won't upgrade from VS 2005 and XP to 2008 and Win7 ;)
Yup, says that guy.
Is this actually resolved now? I can't tell.