Enter Key

V

VJ

I have a window were I display a bunch of Labels. A click event is attached
for each label, when clicked it will display a edit box i.e textbox. If the
enter key is pressed in the textbox I want to the foucs to shift to the next
label in taborder and then fire the click event of that label and display a
editbox. Here is what I tried..and its not working..

The current edit box has a key down event.. with code like this..

If e.KeyCode = Keys.Enter Then
e.Handled = False
SendKeys.Send("{TAB}")
End If

when each label is created.. i have events attached like this...

AddHandler lbl.Click, AddressOf lbl_ShowTb
lbl.TabStop = True
AddHandler lbl.Enter, AddressOf lbl_Enter

and in the lbl_Enter event I have code like this...

lbl_ShowTb(sender, e)

The showTb has code for removing any pending editboxes.. which works for
other conditions.. which is not a problem.

What am I doing worng..? The sendkeys.send is not moving the foucs...?

Thanks
VJ
 
K

Ken Tucker [MVP]

Hi,

Use the keypress event instead.

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

If e.KeyChar = Chr(Keys.Enter) Then
e.Handled = True
SendKeys.Send(Chr(Keys.Tab))
End If

End Sub

Ken
-------------
 
V

VJ

That seems to have removed the behaviour of producing multiple lines within
the text box... but still the Tab key does not change foucs...

VJ
 
K

Ken Tucker [MVP]

Hi,

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

If e.KeyChar = Chr(Keys.Enter) Then
e.Handled = True
Me.SelectNextControl(DirectCast(sender, Control), True,
True, True, True)
End If

End Sub

Ken
 
J

Jay B. Harlow [MVP - Outlook]

VJ,
Is there a reason you are using SendKeys.Send instead of SelectNextControl?
If e.KeyCode = Keys.Enter Then
e.Handled = False
Me.SelectNextControl(sender, True, True, True, True)

Remember that a Label control itself cannot receive the focus so Tabbing to
it does not work, the control after the Label will be the control to tab to.
In other words when you set Label.TabStop to True there is no effect. The
editbox after the Label is the one that gets the focus, not the Label.

If you are attempting to show the TextBox when you Tab to the Label, you
will actually tab to the current TextBox... You need to show the TextBox,
then use SelectNextConntrol.

Hope this helps
Jay
 
V

VJ

Thanks Ken.. I will try this out..

VJ

Ken Tucker said:
Hi,

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

If e.KeyChar = Chr(Keys.Enter) Then
e.Handled = True
Me.SelectNextControl(DirectCast(sender, Control), True,
True, True, True)
End If

End Sub

Ken
 
V

VJ

ahh... i get it... Thanks Jay

VJ

Jay B. Harlow said:
VJ,
Is there a reason you are using SendKeys.Send instead of SelectNextControl?
Me.SelectNextControl(sender, True, True, True, True)

Remember that a Label control itself cannot receive the focus so Tabbing to
it does not work, the control after the Label will be the control to tab to.
In other words when you set Label.TabStop to True there is no effect. The
editbox after the Label is the one that gets the focus, not the Label.

If you are attempting to show the TextBox when you Tab to the Label, you
will actually tab to the current TextBox... You need to show the TextBox,
then use SelectNextConntrol.

Hope this helps
Jay

display
 

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