Sign in to follow this  
nils987

Multiple forms, VS.net 2003 c++.

Recommended Posts

nils987    122
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 this post


Link to post
Share on other sites
TFS_Waldo    146
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 form

this.Visible = false; // Hide first form

while (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 this post


Link to post
Share on other sites
nils987    122
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.

Share this post


Link to post
Share on other sites
superpig    1825
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.

Share this post


Link to post
Share on other sites
nils987    122
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?

Share this post


Link to post
Share on other sites
TFS_Waldo    146
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this