Multiple forms, VS.net 2003 c++.

Started by
5 comments, last by TFS_Waldo 18 years ago
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.
Advertisement
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! =)
:==-_ Why don't the voices just leave me alone?! _-==:
Thanks for your answer I think I understand what you mean.

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.
I still need help with this, thanks.
Quote:Original post by nils987
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?


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.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Quote:Original post by superpig
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.



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?
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
:==-_ Why don't the voices just leave me alone?! _-==:

This topic is closed to new replies.

Advertisement