Handler question

  • Thread starter Thread starter Luhar
  • Start date Start date
L

Luhar

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
 
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
 
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.
 
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
 

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

Back
Top