By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

unload a form (close a form)

P: n/a


Hi,

I have more than one forms in my program, and I would like to for
example, in form1, I will call form2 and in form2 it will call form3.
But the problem is when I call form2.Show, it does show the form2, but
how can I unload form1? If I put form1.close, it will close everything.
:(
In VB, I only have to put
call form2.show
call unload(form1)

I'm new in C#, so could someone help me?

Cheers!
Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Tue, 17 May 2005 01:50:15 -0700, Claudia Fong wrote:
Hi,

I have more than one forms in my program, and I would like to for
example, in form1, I will call form2 and in form2 it will call form3.

But the problem is when I call form2.Show, it does show the form2, but
how can I unload form1? If I put form1.close, it will close everything.
:(

In VB, I only have to put

call form2.show
call unload(form1)

I'm new in C#, so could someone help me?


This is because by default when you create a new WinForm application in C#,
the main method consists of one line of code. That line of code is
Application.Run(new Form1());. The effect of that is that the Application
adds an event handler for the Closed event of the form. In that event
handler it calls ExitThread. So when you close Form1 the application
exits. You would need to remove that line of code and take over
responsibility for when to call Application.Run and when to show Form1, and
when to call Application.ExitThread.
--
Tom Porterfield
Nov 17 '05 #2

P: n/a
iLo

This is because by default when you create a new WinForm application in C#, the main method consists of one line of code. That line of code is
Application.Run(new Form1());. The effect of that is that the Application
adds an event handler for the Closed event of the form. In that event
handler it calls ExitThread. So when you close Form1 the application
exits. You would need to remove that line of code and take over
responsibility for when to call Application.Run and when to show Form1, and when to call Application.ExitThread.
Tom Porterfield


Hi, I have the same problem with Claudia
and I have a simple question..
"You would need to remove that line of code" ...where is this line...?? :)
Thanks..
Nov 17 '05 #3

P: n/a
iLo wrote:
Hi, I have the same problem with Claudia
and I have a simple question..
"You would need to remove that line of code" ...where is this line...?? :)
Thanks..


Re-read my response, I stated exactly where it was. And re-read also as I
stated more was needed than simply removing a line of code.
--
Tom Porterfield
Nov 17 '05 #4

P: n/a
I understand the concept of "taking over" the control of the starting/ending
of the application.

However, the practicality is not necessarily the same as the concept.

Could you direct me to a website or other resource that could provide a good
example of how this is accomplished?

Thanks,
~Dan

"Tom Porterfield" wrote:
On Tue, 17 May 2005 01:50:15 -0700, Claudia Fong wrote:
Hi,

I have more than one forms in my program, and I would like to for
example, in form1, I will call form2 and in form2 it will call form3.

But the problem is when I call form2.Show, it does show the form2, but
how can I unload form1? If I put form1.close, it will close everything.
:(

In VB, I only have to put

call form2.show
call unload(form1)

I'm new in C#, so could someone help me?


This is because by default when you create a new WinForm application in C#,
the main method consists of one line of code. That line of code is
Application.Run(new Form1());. The effect of that is that the Application
adds an event handler for the Closed event of the form. In that event
handler it calls ExitThread. So when you close Form1 the application
exits. You would need to remove that line of code and take over
responsibility for when to call Application.Run and when to show Form1, and
when to call Application.ExitThread.
--
Tom Porterfield

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.