Professional Documents
Culture Documents
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no
registration required.
log in
tour
help
.net
winforms
.net-2.0
5 Answers
In my opinion the main form should be responsible for opening both child form. Here is some pseudo that
explains what I would do:
// MainForm
private ChildForm childForm;
private MoreForm moreForm;
ButtonThatOpenTheFirstChildForm_Click()
{
childForm = CreateTheChildForm();
childForm.MoreClick += More_Click;
childForm.Show();
}
More_Click()
{
childForm.Close();
moreForm = new MoreForm();
moreForm.Show();
}
You will just need to create a simple event MoreClick in the first child. The main benefit of this approach is
that you can replicate it as needed and you can very easily model some sort of basic workflow.
http://stackoverflow.com/questions/3965043/how-to-open-a-new-form-from-another-form
1/4
11/14/2014
into this?
Why do you use f2.ShowDialog(); in the first case and f3.Show() in the second case? superpuccio Feb 21 at
9:22
add a comment
I would use a value that gets set when more button get pushed closed the first dialog and then have the
original form test the value and then display the the there dialog.
For the Ex
http://stackoverflow.com/questions/3965043/how-to-open-a-new-form-from-another-form
2/4
11/14/2014
Form 1 Code
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private bool DrawText = false;
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.ShowDialog();
if (f2.ShowMoreActions)
{
Form3 f3 = new Form3();
f3.ShowDialog();
}
}
Form2 code
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public bool ShowMoreActions = false;
private void button1_Click(object sender, EventArgs e)
{
ShowMoreActions = true;
this.Close();
}
Leave form3 as is
answered Oct 19 '10 at 3:19
rerun
15.6k 2 23 58
add a comment
ok so I used this:
public partial class Form1 : Form
{
private void Button_Click(object sender, EventArgs e)
{
Form2 myForm = new Form2();
this.Hide();
myForm.ShowDialog();
this.Close();
}
}
This seems to be working fine but the first form is just hidden and it can still generate events. the
"this.Close()" is needed to close the first form but if you still want your form to run (and not act like a
launcher) you MUST replace it with
http://stackoverflow.com/questions/3965043/how-to-open-a-new-form-from-another-form
3/4
11/14/2014
This question already has an answer selected, and it was last active over 6 months ago. You may want to
consider leaving a comment in this situation instead of posting another answer. FKunecke Jul 15 '13 at 20:39
add a comment
Try this..
//button1 will be clicked to open a new form
private void button1_Click(object sender, EventArgs e)
{
this.Visible = false;
// this = is the current form
SignUp s = new SignUp(); //SignUp is the name of my other form
s.Visible = true;
}
edited Oct 1 '12 at 5:45
Arun Singh
841 2 9 32
Not the answer you're looking for? Browse other questions tagged c# .net winforms
.net-2.0 or ask your own question.
http://stackoverflow.com/questions/3965043/how-to-open-a-new-form-from-another-form
4/4