Hi all, first post. I am a C# novice, but I have some experience in other C-derived languages.

I am trying to close a Windows Form and open another. This is the code that I am trying to use:

FormChat fm = new FormChat(client, username);
fm.Show();
fm.Activate();
this.Close();

However, both forms close: the new Form closes even before I see it open (I know of it's existance only because of a strategic mbox it opens). If I comment out the this.Close() line then both stay open. So how can I close the current form without closing any children (is that the right word) forms?

Thanks!

Re: Closing a Windows Form, openning another 80 80

I've worked around the problem with this.Hide(), but I feel that it is sloppy. Is there a better way?

Re: Closing a Windows Form, openning another 80 80

Hi,

Check this

Re: Closing a Windows Form, openning another 80 80

Thanks, Clone. It looks like he is doing exactly what I am doing: Hide(). His solution appears cleaner only because it is his intention that both forms should ultimately close, alas, I would like to keep the child open!

Thank you for the link, though. The authour does have some good articles and I'm going to subscribe to his RSS feed. Lots to learn there, for certain. Thanks!

Re: Closing a Windows Form, openning another 80 80

If I understand it is like this:
- you open form1
- then you would like to close form1, and open form2?

or:
- open form1
- open form2
- then close form2, and open form3

This is a bit difference, becuase you have started app. with form1 ( Application.Run(new Form1());)

Re: Closing a Windows Form, openning another 80 80

Open Form1, then close Form1 and open Form2.

There may be a Form3, but only if I can't get an mbox to do what I want (I'm googling that at the moment). In any case, even if there is a Form3, Form2 will remain open.

Thanks.

Re: Closing a Windows Form, openning another 80 80

I see from other examples on Daniweb that Hide() is in fact the correct way to handle the situation. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.