Since I do not have a great reputation for posting an image, I am developing it as a big question.
I have three forms of windows in which the execution of events increases each time a form is created.
1. Form1 (MainForm)
Here I call the second form (SubForm), which contains the user control.
2. Form2 (subform)
Here I call the second form (ChildForm) by clicking on the user control.
3. Form Form3 (ChildForm)
It contains an OK button.
Here is my problem.
- First, I open MainForm and click the button to open the second form (SubForm).
- Now in the second form (SubForm) I click on the user control that shows the third form (ChildForm).
- When I click the OK button in the third form, the form closes.
- Now I close the second form (SubForm) without closing the first form (main form), and click the button in the first form (MainForm) to open the second form (SubForm) again.
- Now I select the user control in the second form (SubForm), and the third form (ChildForm) opens.
- Now, when I click OK in the third form (ChildForm), the event in the second form (SubForm) is fired once, and the third form (ChildForm) is opened four times.
- Now, when I close the second form (SubForm) again and click on the user control and take the third form (ChildForm), the third form (ChildForm) opens three times, etc. etc.
Here is the code in the first form (MainForm)
private void button1_Click(object sender, EventArgs e) { SubForm obj = new SubForm (); obj.ShowDialog(); }
Here is the code in the second form (SubForm) that contains the user control
// Event generation UserControl1.MouseUp += new EventHandler(this.Node_Click); // Event that calls the ChildForm private void Node_Click(object sender, EventArgs e) { ChildForm obj = new ChildForm(); obj.ShowDialog(); }
Here is the code in the first form (MainForm)
private void btnOK_Click(object sender, EventArgs e) { this.Close(); }
Does anyone know why this is happening?
source share