Public Group

# Multiple forms, VS.net 2003 c++.

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

## Recommended Posts

Hi, I was just trying to make a simple windows application in c++ using visual studio.net 2003. I have a simple question. I have my standard form and now I need another form to pop up when I press a certain button in the first form. In the second form the user should be able to fill in IP and Port in two textboxes and then press either ok or cancel. If he presses ok, the second form should disappear and the first form should reappear. And the IP and Port should be access able in the first form. How do I make this? Thanks in advance.

##### Share on other sites
Well, to open another form:

MyForm frm = new MyForm();
frm.Show();

will create/display form from class "MyForm".

And I have made an application or two that passed data between two forms.

First, call "this.Visible = false;" in the main form, to hide it. Then, do this:

MyForm frm = new MyForm();frm.Show();    // Create and show second formthis.Visible = false;      // Hide first formwhile (frm.Created)    // As long as the second form hasn't been closed{}this.Visible = true;     // Re-show the first form

Then, create a function in the second form like "SetParentFrm(FirstFrm frm)", and call it before "frm.Show()", like:

frm.SetParentFrm(this);
frm.Show();

And just create a simple function in the first form that is public, so the second for can call it. Then, handle "OK" click in second form, validate input, and call "parentFrm.PassData(param1, param2);"

I hope you understand what I mean. But I gotta go to bed. Been up for 30+ hrs. LoL.

I hope this helps! =)

##### Share on other sites

But to get this to work I need to include my second form in my first form and my first form in my second form?

I dont get this to work, if I do this I get lots of errors.

##### Share on other sites
I still need help with this, thanks.

##### Share on other sites
Quote:
 Original post by nils987But to get this to work I need to include my second form in my first form and my first form in my second form?

Not necessarily. If you just want the second form to pop up over the first form, and you're happy to keep the first form in the background, then you don't need to include the first form in the second form.

And to be honest, if you want to "swap" forms like TFS_Waldo describes, I wouldn't do it his way. Instead, I'd look at the code that's responsible for displaying the first form, and make that code responsible for hiding/showing any other forms. That code's like the "spine" that binds the different pages of your application together, so it can sensibly refer to every page in the application.

##### Share on other sites
Quote:
 Original post by superpigNot necessarily. If you just want the second form to pop up over the first form, and you're happy to keep the first form in the background, then you don't need to include the first form in the second form.

How? I still need to include it to create the second form dont I? Can you please give me a code example of how to do it?

##### Share on other sites
Thanks for correcting/clarifying me, superpig. =) Sorry. That's just how I did it, but I haven't been using C# very long, so I did what worked at the time. =P

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631428
• Total Posts
3000027
×

## Important Information

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

Sign me up!