multiple controls firing one event from usercontrol
-
hi there, I need to access an unknown number of controls, that may be added by a user to my a usercontrol and each control must fire the same event! i think this is the only way possible that i can do it! for example..imagine a panel and add three buttons to it...then on each mouse enter of each button the same event is triggered, i have tried a number of ways but all failed. please help thanks
-
hi there, I need to access an unknown number of controls, that may be added by a user to my a usercontrol and each control must fire the same event! i think this is the only way possible that i can do it! for example..imagine a panel and add three buttons to it...then on each mouse enter of each button the same event is triggered, i have tried a number of ways but all failed. please help thanks
Create a single method in your code, and tie the event of each control to that method. Christian Graus - Microsoft MVP - C++
-
hi there, I need to access an unknown number of controls, that may be added by a user to my a usercontrol and each control must fire the same event! i think this is the only way possible that i can do it! for example..imagine a panel and add three buttons to it...then on each mouse enter of each button the same event is triggered, i have tried a number of ways but all failed. please help thanks
Or, if your adding these controls dynamically, look into AddHandler[^]. Don't forget to lookup it's opposite, RemoveHandler. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Or, if your adding these controls dynamically, look into AddHandler[^]. Don't forget to lookup it's opposite, RemoveHandler. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Hi, i have been quite busy lately due to exams at uni, but i would just like to say thanks for your advice.... The following code is exactly what i needed Add this code and some controls to a form and on each Mouse_Enter of any control the main event is triggered..excellent:-D
'Every control added to the form cause this event to be raised WithEvents MyDummyControl As Button Public Event MyEvent() ' Declare an event. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim mycontrol As Control 'count number of controls For x As Integer = 0 To Me.Controls.Count - 1 'Associate controls mycontrol = Me.Controls.Item(x) ' Associate an event handler with an event. AddHandler mycontrol.MouseEnter, New EventHandler(AddressOf TriggerMyEvent) Next RaiseEvent MyEvent() ' Raise an event. Catch MyError As Exception 'dont do event End Try End Sub Private Sub TriggerMyEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyDummyControl.MouseEnter End Sub
Thanks again