rp
asked on
vb.net selstart, sellenght
Is there any way to activate the selstart/sellenght for all textbox in form automatically.
You would need to add a javascript function to each textbox's onfocus event to set the selStart and selLength values.
Can you give more details?
If you want all text to be selected upon entry try something like:
If you want all text to be selected upon entry try something like:
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
TextBox1.SelectAll()
End Sub
Hmm...WinForms or WebForms? =D
Good point, which is it?
ASKER
Winforms
ASKER
Instead of defining all GotFocus each textbox, I would do it automatically
Two ways:
(1) Add all of them after the "Handles" clause.
(2) Wire them up at run-time using AddHandler().
In both cases, use the "sender" parameter to determine which box fired the event.
Example of #1 with three TextBoxes:
*You can select all of them on the form, hit the lightning bolt, then select the GotFocus() event to add them all at once*
(1) Add all of them after the "Handles" clause.
(2) Wire them up at run-time using AddHandler().
In both cases, use the "sender" parameter to determine which box fired the event.
Example of #1 with three TextBoxes:
*You can select all of them on the form, hit the lightning bolt, then select the GotFocus() event to add them all at once*
Private Sub AllTextBoxex_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus, TextBox3.GotFocus
Dim tb As TextBox = CType(sender, TextBox)
tb.SelectAll()
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can generalize the function so you can use it for all GotFocus functions for all of your textboxes.
Private Sub GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus ...
CType(sender, TextBox).SelectAll()
End Sub