Page 1 of 1
Multiple Forms in C# [SOLVED]
Posted: Sat Mar 10, 2012 12:49 am
by mattykins
So i'm working in Windows Forms C# and in a program i'm making there is multiple forms. How would i get it so when i press a button, one form hides and another shows? So there is only 1 form showing at a time. Thanks in advanced!

Re: Multiple Forms in C#
Posted: Sat Mar 10, 2012 1:04 am
by Jackolantern
In C#, forms are handled just as any other object is. You first instantiate a new form, and then call the form.show() method to show it in a non-modal way, or form.showDialog to show it in a modal fashion. You can then call form.hide() on the old form to hide it. Or you can use form.close() to actually remove it from memory.
Here is the MSDN entry for the Form class, which has a full listing of the properties and methods you can use in your applications on the Form class.
Re: Multiple Forms in C#
Posted: Sat Mar 10, 2012 1:24 am
by mattykins
I had tried that, when I click the start button it runs this code
Code: Select all
formCharCre f = new formCharCre();
f.Show();
Titlescreen t = new Titlescreen();
t.Hide();
However it still doesn't hide the Titlescreen form.
Re: Multiple Forms in C#
Posted: Sat Mar 10, 2012 5:07 am
by Jackolantern
Because you just created a new TitleScreen and hid it without it ever being shown. Instead, inside the TitleScreen class, try:
Re: Multiple Forms in C#
Posted: Sat Mar 10, 2012 5:34 am
by mattykins
Thanks, worked great

Re: Multiple Forms in C# [SOLVED]
Posted: Sat Mar 10, 2012 5:54 am
by Jackolantern
Awesome! You're most welcome
