By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

Handler question

P: n/a
I have several textboxes and I want one dbl click handler to be used for all
of the textboxes. How do I get all of the text boxes to use the same dbl
click
handler?

Kim
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Private Sub DoubleClickHandler(ByVal sender As Object, ByVal e As
System.EventArgs) _

Handles TextBox1.DoubleClick, TextBox2.DoubleClick, TextBox3.DoubleClick,
TextBox4.DoubleClick

Dim tb As TextBox = DirectCast(sender, System.Windows.Forms.TextBox)

MsgBox(String.Format("Text in {0}:{1}{2}", tb.Name, Environment.NewLine,
tb.Text), _

MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "You double-clicked " +
tb.Name)

End Sub

hth,

Luhar

"Kim C" <ki***@cox.net> wrote in message news:EaeOc.137$73.30@lakeread04...
I have several textboxes and I want one dbl click handler to be used for all of the textboxes. How do I get all of the text boxes to use the same dbl
click
handler?

Kim

Nov 20 '05 #2

P: n/a
private sub myDoubleClick(byval sender as object, byval e as
System.EventArgs) handles _
textbox1.DoubleClick, textbox2.DoubleClick, textbox3.Doubleclick
'your common doubleclick handling code here
end sub

Or...

private sub myDoubleClick(byval sender as object, byval e as
System.EventArgs)
'your common doubleclick handling code here
end sub

AddHandler textbox1.DoubleClick, AddressOf myDoubleClick
AddHandler textbox2.DoubleClick, AddressOf myDoubleClick
AddHandler textbox3.DoubleClick, AddressOf myDoubleClick

in the second method, you could loop through all your controls, check
whether its a textbox
and then use AddHandler.

something like...
for each oControl in Me.Controls()
if typeOf oControl is TextBox then
AddHandler oControl.DoubleClick, AddressOf myDoubleClick
end if
next oControl

the syntax for the above might me wrong...sorry. Just wanted to give you the
idea..

hope this helps..
Imran.
"Kim C" <ki***@cox.net> wrote in message news:EaeOc.137$73.30@lakeread04...
I have several textboxes and I want one dbl click handler to be used for all of the textboxes. How do I get all of the text boxes to use the same dbl
click
handler?

Kim

Nov 20 '05 #3

P: n/a
Hi Kim,

The rest te same as the other answers from Luthar and Imran a quick method
to set the handler to all textboxes.

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
If TypeOf ctr Is Textbox then
AddHandler ctr.DoubleClick, AddressOf MyDoubleClick
end if
doSet(ctr)
Next
///

I hope this helps?

Cor
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.