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:
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.
精彩评论