开发者

How do i check if the game was closed?

I am trying to create a game and now i want to check if the game开发者_开发技巧 is being closed so i will send a message to the server, how do i do it? (XNA)


The correct method is, in your Game class, override OnExiting:

protected override void OnExiting(object sender, EventArgs args)
{
    // Do stuff here...

    base.OnExiting(sender, args);
}

The documentation for this method is here: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.onexiting.aspx

Alternately you could attach an event to Game.Exiting.

Or you could override EndRun, although this doesn't seem to fire on Windows if the user exits with Alt+F4.


Try this (found on this site)

protected override void LoadContent() 
{ 
    Form f = Form.FromHandle(Window.Handle) as Form; 
    if (f != null) 
    { 
        f.FormClosing += f_FormClosing; 
    } 
    base.LoadContent(); 
} 

void f_FormClosing(object sender, FormClosingEventArgs e) 
{ 
    // your code here
}  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜