Jump to content
  • Advertisement
Sign in to follow this  
Koolchamp

[C#] Opening a new form from an existing form

This topic is 4424 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello to whoever reads this, :) Im creating a program in Visual C#. What I want to do is when the user clicks a button, it opens up a new form (that has a bunch of new stuff on it). This is, I dont know how I would open up that new form. Ive looked at a few tutorials off the interenet, but I can't seem to find anything about this. If anyone could help me with this problem, I would really appriciate it. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Go to project and add a new form, say named From2.

Use the form editor to add all the stuff you want on it.

In your button_click event add..
Form2 form2 = new Form2();
form2.Show();

That will do it.

theTroll

Share this post


Link to post
Share on other sites
First, add a new Form object to the project. Then, from the main form class, just do this (on button click or something):

Form2 newForm = new Form2();
newForm.Show();

=)

Share this post


Link to post
Share on other sites
What do you mean? What does that do?

Im new to programming in Visual C# and windows programming in general. (been learning C++ and making console apps at this point). Venturing out with C# but I really dont know that much.

Share this post


Link to post
Share on other sites
This tells your new form that it is owned by your main form. I don't know whether its strictly necessary but I have seen this done many times before.

Share this post


Link to post
Share on other sites
you DO NOT want all forms to be ownedby default "just because" ... there is a difference between owned and non-owned forms, and you must pick the right one for your desired behavior.

2 non-owned forms are both peers, either one can be clicked and made to be active / on-top and each may be minimized or closed seperately.

If one form is set as the owner of the other, than the owned form is minimized or closed with the parent form, and the owned form may never be behind the parent form. (The example in the msdn is for things like find windows and floating toolbars).

Also, if you want dialog box behavior (modal) where the new form must be closed before the user can go back to the main form, use ShowDialog() when you show it instead of the normal Show() method.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!