Raise Events in a control inside another

G

Guest

In a VB.NET windows forms
I have a custom control which I have added a number of instances to a panel
control. I want to raise a event when one of the controls on one of the
custom controls is changed etc. and trap this event in the Form code where
the panel is

Each copy of the control is created and added to the panel using items.add()
 
G

Guest

Hi Martin,

You basically want to
1. Create a method on the form that you want to run when the event on any of
the controls is raised.
2. Use AddHandler to link each of the custom controls to the method created
in 1.

For example, lets say that you have a control called MyCustomControl, and it
has an event called MyEvent, that passes a reference to the MyCustomControl
that raises the event.

Public Class frmTest

' This is the method that the
Sub HandleCustomControlEvents(ByRef oControl As MyCustomControl)
MessageBox.Show(oControl.Name & " fired its event")
End Sub

Private Sub frmTest_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim cntControl As MyCustomControl

cntControl = New MyCustomControl()

AddHandler cntControl.MyEvent, AddressOf HandleCustomControlEvents

Me.Controls.Add(cntControl)

End Sub

End Class

Hope this helps
Rick Hodder
 

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

Top