// user control
public partial class MyUserControl : UserControl
{
public event EventHandler SomethingHappened;
public MyUserControl()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OnSomethingHappened();
}
protected void OnSomethingHappened()
{
if (SomethingHappened != null)
SomethingHappened(this, new EventArgs());
}
}
'// parent form
private void Form1_Load(object sender, EventArgs e)
{
myUserControl1.SomethingHappened += new EventHandler(myUserControl1_SomethingHappened);
}
void myUserControl1_SomethingHappened(object sender, EventArgs e)
{
MessageBox.Show("Something happened");
}
|