Textbox MouseDown

L

lmefford

Is there a way to modify all textboxes on a form so that when you
click on any of them you process the SelectAll() function.

For exaple, let's say I've created a form with 30 textboxes. These
textboxes when clicked on, will select all of the text inside of them
using the textbox.selectall(). I'm hoping to do this without creating
30 different Subs. How do I do it?
 
L

lmefford

Is there a way to modify all textboxes on a form so that when you
click on any of them you process the SelectAll() function.

For exaple, let's say I've created a form with 30 textboxes. These
textboxes when clicked on, will select all of the text inside of them
using the textbox.selectall(). I'm hoping to do this without creating
30 different Subs. How do I do it?

Ok, I found a way, but it's still pretty lengthy.
I merely used a single mousedown event for one textbox and added a few
textboxes to the handles and then proceeded to use the sender.

Private Sub uione_MouseDown_
(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) _
Handles uione.MouseDown, _
uitwo.MouseDown, _
uithree.MouseDown, _
uifour.MouseDown
sender.SelectAll()
End Sub

I kind of want to avoid that cause it seems a little slow and I'm
wanting to streamline the code. But if that's the way to do it, then
so be it.
 
G

Guest

why not just have each of the textboxs' Click events go to the same function,
ex, if the textboxes are in an array

For Each txt As TextBox In arrInput

AddHandler txt.Click, AddressOf ClickEventHere

Next

then in the click event, cast Sender to a textbox and select all...

Private Sub ClickEventHere(ByVal sender As Object, ByVal e...)

Dim txt As TextBox = DirectCast(sender, TextBox)

txt.SelectAll()

End Sub

hope this helps
 

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