Link to home
Start Free TrialLog in
Avatar of directxBOB
directxBOBFlag for Ireland

asked on

Easiest Way to close a Window

I have a window, that has a close button, I would like to make it close. So I have the method:

    private void m_CloseButton_Click(object sender, System.EventArgs e)
    {
      components.Dispose();
    }

is Components.Dispose();

The easiest way or is there another way?
ASKER CERTIFIED SOLUTION
Avatar of jvn222
jvn222

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tsay
tsay

You can use two methods. You should use the close method on the current form object. To call this, just type this.close(); The close method will displose all resources used by the form.

You can also use Application.Exit(); but in that case the form_Close and form_Closing events are NOT triggered so be carefull with this as code won't be executed in these events.

hth
this.Dispose();
--pradeep
Hi tyr this
using System.Threading;

and add
Thread.CurrentThread.Abort();

--pradeep
Avatar of vo1d
what do you wanna close? only a specific form or the whole application with different forms?