Solved

Passing an object using Add event handler

Posted on 2010-09-09
3
334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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