|
-
Mar 17th, 2010, 02:28 PM
#1
Thread Starter
Junior Member
[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?
-
Mar 17th, 2010, 02:58 PM
#2
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.
-
Mar 17th, 2010, 03:05 PM
#3
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?
-
Mar 17th, 2010, 03:07 PM
#4
Re: Stopping a label from receiving focus
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
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Mar 17th, 2010, 03:07 PM
#5
Thread Starter
Junior Member
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.
-
Mar 17th, 2010, 03:10 PM
#6
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.
-
Mar 17th, 2010, 03:11 PM
#7
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?
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Mar 17th, 2010, 03:29 PM
#8
Addicted Member
Re: Stopping a label from receiving focus
Just curious, what is your code for moving from one control to another with the enter key.
-
Mar 17th, 2010, 03:32 PM
#9
Thread Starter
Junior Member
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.
-
Mar 17th, 2010, 03:39 PM
#10
Re: [RESOLVED] Stopping a label from receiving focus
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.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Mar 17th, 2010, 03:40 PM
#11
Addicted Member
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
-
Mar 17th, 2010, 03:45 PM
#12
Addicted Member
Re: [RESOLVED] Stopping a label from receiving focus
 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?
-
Mar 17th, 2010, 03:51 PM
#13
Re: [RESOLVED] Stopping a label from receiving focus
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.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Mar 17th, 2010, 04:04 PM
#14
Addicted Member
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
-
Mar 17th, 2010, 06:31 PM
#15
Re: Stopping a label from receiving focus
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|