简体   繁体   English

我如何在申请表格前关闭XNA应用程序? C#

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

I'm doing XNA application. 我正在做XNA应用程序。 I use Game1.cs (XNA file) and MainForm.cs (form file) 我使用Game1.cs(XNA文件)和MainForm.cs(表单文件)

Program.cs 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 单击“ X”按钮时,我尝试关闭MainForm.cs中的所有应用程序

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

Unfortunally, Game1.cs is working all time. 不幸的是,Game1.cs一直在工作。

I also try to add void Quit() in Game1.cs and active its when X is clicked. 我还尝试在Game1.cs中添加void Quit()并在单击X时将其激活。

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

How can I close Game1 by pressing X Button? 如何通过按X按钮关闭Game1?

In your X button handler call: 在您的X按钮处理程序调用中:

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. 原因是未调用MainForm_FormClosed是由于未关闭窗口而导致窗体未关闭。 Application.Exit() will do that Application.Exit()会做到这一点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM