Terminating a windows form

  • Thread starter Thread starter Xarky
  • Start date Start date
X

Xarky

Hi,

I am creating a windows form, and when a specified event occurs
(button click), I am hiding the windows form and opening a new windows
form. When opening the new windows form and closing it, the main
windows form would still be running in the background and never
terminating. How can I terminate the old window form from the new
created window.

I hope someone out there understands my problem.



Thanks and Regards
 
Xarky said:
Hi,

I am creating a windows form, and when a specified event occurs
(button click), I am hiding the windows form and opening a new windows
form. When opening the new windows form and closing it, the main
windows form would still be running in the background and never
terminating. How can I terminate the old window form from the new
created window.

I hope someone out there understands my problem.

You only need to store the instance of the hidden window in a variable that
is accessible from your new window. If your new window is then closed it
calls Close() of the hidden window. But maybe I don't understand your
problem.

Boris
 
Xarky,

Hide() command will remove window from visibility only. Its still in the
memory.

Try this in your button click.

//first hide form 1
Form1.Hide()
//show the new form as modal
Form2.ShowDialog();
//when form 2 is closed, destrory form1
Form1.Close();
 
Hi,

When the initial form of a Windows application get's closed, then the whole application is terminated.

Hence, if the form you want to close is the startup form, then you will have to hide it, rather than close it.
 
Back
Top