开发者

Preventing a dialog from showing multiple times

I have the following piece of code:

        else if (state.IsKeyDown(Keys.H))
        {
            Help help = new Help();
            help.ShowDialog();
        }

For some reason, if I hold 开发者_开发技巧the H key, the dialog opens multiple times:

Preventing a dialog from showing multiple times


If you are using XNA for your input, then save the previous KeyState and then do a check to see if the previous KeyState is released and the current KeyState is pressed.

This link will help you correctly resolve the problem.


Create the Help dialog as a member of your class. Initialize it once, and change your code for this:

    else if (state.IsKeyDown(Keys.H))
    {
        if (!help.Visible)
             help.ShowDialog();
    }


Maybe you use the KeyPress Event, and you could use the KeyUp Event (or the KeyDown).

Another workaround would be to use a singleton pattern on your Help Popup.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜