views:

46

answers:

4

How do I kill a windows form application other than clicking the x button. More specifically, I need to close the program from a menu option. I am coding this in c# 2010.

+1  A: 

Use the Close method on your main form.

Femaref
+1  A: 

You mean Application.Exit()? It can be called from any block of code, such as a menu option or a button click.

David
A: 

You need to assign a custom handler to your menu item's OnClick event handler:

(Pseudocode)
    MenuItem_CloseWindow.OnClick += new OnClickHandler(YourMethodHere)
    ....
    YourMethod(object sender, EventArgs e)
    {
       this.Close();

    }

That should do the trick.

Jas
A: 

All Windows Forms come with the built-in ability to close them using the System Menu. Just press ALT + SPACE and it will show the Close option unless you have set the ControlBox property to False.

zainnab