I create a event and handle it on the Form
User Control Code:
public event EventHandler ButtonClick; private void button1_Click(object sender, EventArgs e) { if (this.ButtonClick != null) this.ButtonClick(sender, e); } Form Code:
private Usercontrol1 sampleUserControl = new Usercontrol1(); public Form1() { InitializeComponent(); sampleUserControl.ButtonClick += new EventHandler(this.UserControl_ButtonClick); } private void UserControl_ButtonClick(object sender, EventArgs e) { //sample event stuff this.Close(); Form2 F2 = new Form2(); F2.Show(); } but the event does not firing. What must be the problem?
sampleUserControlinstance is different instance ofUsercontrol1than the one which you have added to the form. You dont seem to be addingsampleUserControlinstance to the form.