Link to home
Start Free TrialLog in
Avatar of _Tommy_b
_Tommy_b

asked on

Passing an object using Add event handler

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

ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of _Tommy_b
_Tommy_b

ASKER

Cant belive how simple that was... some time you look for something complicated when infact its so simple.

Thanks Carl :)
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.