HI,
You need to create an event handler for the button-event of the usercontrol and fire it from the click event of the actual button.
class MyControl : UserControl
{
public delegate void ButtonClickedEventHandler(object sender, EventArgs e);
public event ButtonClickedEventHandler OnUserControlButtonClicked;
}
Now you need to listen to the event of the actual button:
class MyControl : UserControl
{
public delegate void ButtonClickedEventHandler(object sender, EventArgs e);
public event ButtonClickedEventHandler OnUserControlButtonClicked;
public MyControl()
{
_myButton.Clicked += new EventHandler(OnButtonClicked);
}
private void OnButtonClicked(object sender, EventArgs e)
{
if (OnUserControlButtonClicked != null)
OnUserControlButtonClicked(this, e);
}
}
From the main form (owner) you can now listen to the event:
public DemoForm : Form
{
public DemoForm()
{
_myUserControl.OnUserControlButtonClicked += new EventHandler(OnUCButtonClicked);
}
private void OnUCButtonClicked(object sender, EventArgs e)
{
MessageBox.Show("Hello");
}
}
Thanks