Solved

Passing an object using Add event handler

Posted on 2010-09-09
3
329 Views
Last Modified: 2012-05-10
I have a form were there a number of textboxes which are created on a form dynamically, the number of which varies according to initial parameters.

Due to the nature of data that the user has to input the text must be formatted to a set format on the 'textbox.leave' event

the attached code works perfectly for this textbox as there is no requirement for information from the textbox that raised the event. Is there some way to use a method like the 'Directcast()' method to obtain properties from the textbox which triggered the event?

Thanks,
Thomas

'' This code in in the form.load eventArg after the code that creates the synamic textboxes



        For Each ctl As Control In Me.Controls

            If TypeOf ctl Is TextBox Then

                AddHandler ctl.Leave, AddressOf tbleave

            End If

        Next



    End Sub



    Sub tbleave()

        MessageBox.Show("The user has left this textbox")

    End Sub

Open in new window

0
Comment
Question by:_Tommy_b
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 33640650
Just change the signature of your handler to the following then you can access the corresponding control via "sender":
Private Sub tbleave(ByVal sender As System.Object, ByVal e As System.EventArgs)

Open in new window

0
 

Author Comment

by:_Tommy_b
ID: 33640721
Cant belive how simple that was... some time you look for something complicated when infact its so simple.

Thanks Carl :)
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 33641073
To be honest I'm a little surprised the complier didn't pick up on it, the C# compiler would have complained about the method not matching the expected signature.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now