Reputation: 6550
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:
Upvotes: 1
Views: 450
Reputation: 48537
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.
Upvotes: 4
Reputation: 813
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();
}
Upvotes: 2
Reputation: 10359
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.
Upvotes: 0