unload a form (close a form)

  • Thread starter Thread starter Claudia Fong
  • Start date Start date
C

Claudia Fong

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
 
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.
 
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..
 
iLo said:
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.
 
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
 
Back
Top