K. Maliszewski
K. Maliszewski

Reputation: 333

How I can close XNA application before the Form? C#

I'm doing XNA application. I use Game1.cs (XNA file) and MainForm.cs (form file)

Program.cs

MainForm mainForm = new MainForm();
mainForm.Show();

Game1 game = new Game1(mainForm);
game.Run();

When "X" button is clicked I try to close all application in MainForm.cs

private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
    Application.Exit();
}

Unfortunally, Game1.cs is working all time.

I also try to add void Quit() in Game1.cs and active its when X is clicked.

public void Quit()
{
    this.Exit();
}

How can I close Game1 by pressing X Button?

Upvotes: 0

Views: 86

Answers (1)

user585968
user585968

Reputation:

In your X button handler call:

Application.Exit();
this.Exit();

The reason being was that MainForm_FormClosed was not called due to the form not closing due to a close window not being posted to it. Application.Exit() will do that

Upvotes: 1

Related Questions