I have a main form that has multiple buttons on it that will allow a user to open other forms. Each of these forms has a button on them that will allow the user to return back to the main form. How can I do this so that they are all part of the same instance? Since my main Program.cs file is a static file, I thought that if I instantiated the main form in my Program.cs file like this:
static class Program
{
P90xScheduleForm ScheduleObjectForm = new P90xScheduleForm();
that I would be able to access the main form from the other forms like this:
private void btnGoToSchedule_Click(object sender, EventArgs e)
{
ScheduleObjectForm.Show();
this.Hide();
}
but I get an “The name ‘ScheduleObjectForm’ does not exist in the current context” error. I also tried adding “public static” in front of the instantiation statement in the Program.cs file but that didn’t help.
I’m at a loss of what to do. Trying to instantiate the main form in each of the sub-forms creates new instances.
Maybe I’m just getting too far ahead of myself. This is beyond where we are in class but I was hoping that if I got adventurous and started making my own programs (in addition to my homework of course) that it would help me understand things better.
That’s not the way you do it. I assume it’s winforms.
You have to instantiate one of the forms(the main form) firs.
Then when you click some of it’s buttons you can show other forms like this.
When you’ve shown the second form you can ‘go back’ to the main form by closing it.
Once you close the main form your app will exit.