Is there a way to invoke (by code) the click event of the "x" on the top right corner of a Form? To be "as if" a user clicked on that?
Ps. I don't want a function that does this.Close()
I read the other answer, but It seems that Application.Exit(); Application.ExitThread(); Environment.Exit();
aren't showing a different behaviour.
In particular, my application works like this:
Main
{
using (Form1 f = new Form())
{
f.Show();
}
using(Game1 game = new Game1())
{
// Create game
game.Run(); //Xna Framework
}
// Do something
}
Note that I don't see the code of Run()
because it is inside the Xna Framework.
Ok, inside my game, in a function I want to exit from it letting Run()
to return.
If I do:
this.Exit(); // Game.Exit()
Or the other three possibilities above, the Whole application closes and //Do something
isn't executed.
BUT, if I press the "x" on the window of the game, it works.
I can't understand why and I can't understand how to reproduce the "x" click programmatically.