Reputation: 1907
I am working on a project and so far it works fine. I have 3 forms and there will be more then, but now to the problem:
When the program starts Form1 will be shown. On a button I call this to open a new form:
Form2 frm = new Form2();
frm.ShowDialog();
Well, this works fine. Form2 will be shown in front of Form1 and if I close it Form1 is again the main form.
In Form2, I want to do the same, now, but Form2 should be closed and Form3 should be in the front. Well, this is not very difficult, but when I call it like that...
Form3 frm = new Form3();
frm.ShowDialog();
this.Close();
... Form2 will not close, because of ShowDialog. What can I do? I want that Form3 is in the front, Form2 is closed and Form1 is still there, but I cannot click on it, as Form3 should be called with ShowDialog.
At the moment Form3 is shown over Form2, but I want that it is shown over Form1. What can I do to solve this?
Of course the forms have other names, it is just to make it easier to understand.
Here you can see two pictures for understanding it better:
This is how it looks: http://www.directupload.net/file/d/3508/xmy99iwq_png.htm
Form2 is visible, but I want it to be closed.
Like here:
http://www.directupload.net/file/d/3508/qjvy42wq_png.htm
But I want that Form3 is in the front and you cannot click on Form1, like I called Form3 with ShowDialog in Form1.
Upvotes: 1
Views: 159
Reputation: 203812
Don't have Form1
call Form2.ShowDialog
. Have it call some other methods instead. Add a new method to Form2
that does what Form2
should do when shown, such as this:
public class Form2 : Form
{
public void Display()
{
ShowDialog();
Form3 dialog = new Form3();
//TODO pass in parameters
dialog.ShowDialog();
}
}
Another option would be to have some entirely separate class handle this, possibly Form1
, or possibly some other type that is essentially a public "wrapper" to Form2
and Form3
, so that users of those forms (i.e. Form1
) only ever use this wrapper class that would look something like this:
public class Foo //TODO give better name
{
public void ShowPopups()
{
Form2 firstDialog = new Form2();
firstDialog.ShowDialog();
Form3 secondDialog = new Form3();
//TODO pass in parameters
secondDialog.ShowDialog();
}
}
Upvotes: 1