I know how to go to another form in modal mode just like what I did below:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Form2 myNewForm = new Form2();
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
myNewForm.ShowDialog();
}
}
This is my second form, how do I go back to the previous form?
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
// what should i put here to show form1 again
}
}
I use a static Form value Current in all my multiple form apps.
Then in Form2
Then you can from your button click do,
When you call
ShowDialog
on a form, it runs until the form is closed, the form'sDialogResult
property is set to something other thanNone
, or a child button with aDialogResult
property other thanNone
is clicked. So you could do something likeAlthough if you're not doing anything but returning from the form when you click the button, you could just set the
DialogResult
property on Form2.button1 in the form designer, and you wouldn't need an event handler in Form2 at all.