In regular XNA the Game
class calls your Draw
and Update
functions regularly (usually at 60 frames per second).
The XNA WinForms samples work slightly differently. There is no update/draw loop. Instead all you get is a Draw
function. And that is only called when the control needs redrawing. This means that:
You're not given a chance to regularly call Keyboard.GetState()
, if that is how you are doing keyboard input.
Even if you are using event-driven (non-XNA) input, your window won't be redrawn regularly so you might not actually see the results of your input until the XNA control is eventually redrawn much later.
Fortunately there is a way to force the control to redraw rapidly. Take a look at the second of those WinForms samples. You will find it is animating (in other words: it is updating frequently). How does it do it? Take a look at this code from ModelViewerControl.cs
:
protected override void Initialize()
{
// Start the animation timer.
timer = Stopwatch.StartNew();
// Hook the idle event to constantly redraw our animation.
Application.Idle += delegate { Invalidate(); };
}
It uses a Stopwatch
to track how much time has elapsed (because there's no Game
class to do it for you). And it invalidates on the Application.Idle
event - in other words, whenever it's not busy processing something, it asks to be redrawn.
(Of course, this is already explained in the documentation for that first WinForms sample. At the bottom, under "Animation".)
Alternative bonus answer: There is nothing stopping you from making use of OpenFileDialog
from WinForms within a regular XNA game. Just add a reference to System.Windows.Forms
, create an instance of the object, set the appropriate properties on it, and call ShowDialog()
.