This project is read-only.

Xen and Windows Form

Aug 23, 2009 at 4:31 AM

I'm creating a tool to help me create my game, a UI editor. I want to make something similar to the form designer in Visual Studio.

So I've made a toolbox, a treeView to represent the hierarchy of screen elements, and a propertyGrid. And to see the UI I'm creating, I use a Xen.WinFormsHostControl, like in the tutorials.

The problem is that some controls like the propertyGrid and the treeview won't draw them self, I have to move or resize the window to get them to draw again. For exemple, if I change a property from my propertyGrid, the change is made, the object is really updated with the new value, but my propertyGrid still shows the old value until I move/resize the window.

To fix this I subscribed to the Paint event of the Xen.WinFormsHostControl and call Refresh() on all child controls of the form except for the WinFormsHostControl. So now all controls redraw. But now parts of the window flash annoyingly. Like if the paint events were now out of sync.

I'm also using the DockPanel suite library but even if I don't use it and only use normal window form controls, I get the same behaviour.


Does anyone know how to fix it? As anyone tried to use Xen with windows form?

I thought to turn on vsync when my app start but I don't know how. SetupGraphicsDeviceManager(..) get a null GraphicsDeviceManager so I can't do it.

Sep 1, 2009 at 5:30 PM

I've fixed it, I don't know if it's the best solution, but for now it works.

I've disabled the AutoRedraw property of the Xen.WinFormsHostControl.

Now it only draws when the control is invalidated.

Then created a Timer and made it call Xen.WinFormsHostControl.Invalidate() every 16 ms.

Now I can continue working on the actual tool...

Sep 1, 2009 at 8:57 PM

Iarus, sorry I couldn't reply before you found a solution.

However I will mention a few things,
You can set win form controls to be double buffered to avoid flashing - however it's not the most reliable thing, and it can be a bit tricky sometimes to do. You often have to set the control style..
Also, a property grid will not automatically refresh changes in the object - it can't do this. It will only refresh when told or when it's target changes (sorry if I have I misinterpreted the problem)

Vsync should always be enabled with a winforms app. However that code is very 'beta' as it's mostly a refactoring of the MS XNA winforms code.