I'm able to get my first form, titled "FieldReprogrammingSoftware" to close and another form called "Setup" to open using the following code.
Setup fh = new Setup();
fh.Show();
this.Hide();
However I can't seem to do the same type of thing to get back to FieldReprogrammingSoftware because that name isn't even an option in the Setup code. If I try to just type FieldReprogrammingSoftware I get an error saying:
The name 'FieldReprogrammingSoftware' does not exist in the current context
Any Ideas?
Please keep in mind that I'm a noob to C#.
NVM, I just found out that for this product it is ok to have the FieldReprogrammingSoftware form stay open while the Setup form is up so I'm now just using
Setup fh = new Setup();
fh.Show();
on the FieldReprogrammingSoftware form and
this.close()
on the setup form. God this was alot easier to do in VB
And the namespace for both forms is FieldUpdate, which is what my Solution is called.
In the Setup form you can use this:
private void button1_Click(object sender, EventArgs e)
{
Application.OpenForms[0].Show();
this.Hide(); // or this.Close();
}
this will show the first form again. "0" is the index of the application's main form.
You either have to pass in the instance of the main form to Setup
or create a static variable to hold the main form in.
You can also subscribe to Setup
Form Closed event and then show the form again.
Like so
Setup setupForm = new Setup();
setupForm.Show();
setupForm.FormClosed += (o,e) => this.Show();
this.Hide();
Edit for .NET 2.0
Setup setupForm = new Setup();
setupForm.Show();
setupForm.FormClosed += new FormClosedEventHandler(setupForm_Closed);
this.Hide();
void setupForm_Closed(object sender, FormClosedEventArgs e)
{
this.Show();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With