I wanted to change the behavior of a text box so that when entering the text box it would highlight the full string inside.
The code works fine, but if I set the forms TopLevel to False so the form acts as a control or MdiChild then all it will do is highlight the text. You can no longer click to position the cursor. If I step through the code it acts normally(I see it flash as it repositions the cursor), but some how reselects the text without steping through the code that is causing it. Any ideas why this happens and how to stop it?
-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
Code:
Private Sub location_tb_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles location_tb.Enter
Dim tb As TextBox = CType(sender, TextBox)
If MouseButtons = Windows.Forms.MouseButtons.None Then
tb.SelectAll()
_HadFocus = True
End If
End Sub
Private Sub location_tb_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles location_tb.MouseUp
Dim tb As TextBox = CType(sender, TextBox)
If _HadFocus = False And tb.SelectionLength = 0 Then
_HadFocus = True
tb.SelectAll()
End If
End Sub
Private Sub location_tb_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles location_tb.MouseDoubleClick
Dim tb As TextBox = CType(sender, TextBox)
If _HadFocus = True And tb.SelectionLength <> 0 Then
tb.SelectionStart = 0
tb.SelectionLength = 0
_HadFocus = True
tb.SelectAll()
End If
End Sub
Private Sub location_tb_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles location_tb.Leave
_HadFocus = False
End Sub
-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!