J Trahair
Well-known member
I have a normal form and normal textboxes. When the focus passes to a one-line textbox with text in it, I want to force the text to be selected and highlighted. When the focus passes to a multi-line textbox, I want to force the text to NOT be selected or highlighted, and the cursor to be at the end.
I have the code
In this case (multi-line) the textbox is set for not selecting the text.
However, this only works after you have TABbed into the textbox, not when you press the Enter key (I have the code:
which handles the Enter key press).
After the initial TAB, the code works fine when you use the Enter key. How can I overcome the 'use TAB key first' problem? Thank you in advance.
I have the code
HTML:
Private Sub TextBoxMultiLines_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxMultiLine1.Enter, TextBoxMultiLine2.Enter etc. etc.
'Either:
'CType(sender, TextBoxMultiLine1).SelectAll()
'or:
CType(sender, TextBox).SelectionLength = 0
End Sub
However, this only works after you have TABbed into the textbox, not when you press the Enter key (I have the code:
HTML:
Private Sub TextBoxes_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress, TextBox2.KeyPress etc. etc.
If e.KeyChar = Chr(Keys.Return) Then
SendKeys.Send("{TAB}")
e.Handled = True
End If
End Sub
After the initial TAB, the code works fine when you use the Enter key. How can I overcome the 'use TAB key first' problem? Thank you in advance.