Reputation: 248
I am using VB 2010. I have 20 TextBox
controls in my form. I turned them to TextBox
array.
Here is the code:
Dim TbArray(19) As TextBox
Private Sub Form7_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
TbArray(0) = TextBox1
TbArray(1) = TextBox2
...
TbArray(19) = TextBox20
It works properly. I want my program to select all the text on the TextBox
control which got focused.
How can i know which TextBox
control has been selected? I mean there is no Private Sub TbArray(i)_GotFocus
in the dropdown menu of vb designer.
Upvotes: 0
Views: 2852
Reputation: 54532
To expound on what Akram said,
For x = 0 to 19
AddHandler tbarray(x).GotFocus, AddressOf TextBox_GotFocus
Next x
Private Sub TextBox_GotFocus(sender As Object, e As System.EventArgs)
Dim tb As TextBox = CType(sender, TextBox)
tb.SelectAll()
End Sub
Upvotes: 1
Reputation: 8355
So you want the text inside the TextBox to get highlighted when it gets focus? Sounds like a job for JavaScript to me. Should be fairly simple using jQuery or something similar
Upvotes: 0
Reputation: 14781
Handle the TextBox.GotFocus event of all the TextBox
controls using one event handler method. Use the following:
Dim focusedTextBox as TextBox = CType(sender, TextBox)
Upvotes: 1