I have a project that I have been working on for a long time using XNA 4.0. Obviously, MS abandoned XNA a very long time back, so I thought I’d move on to MonoGame. This has worked quite painlessly, but the result has been a garbled mess.
The program is a WinForms application written in VB.NET. When the program starts up, a full-screen form is created and a series of icons are drawn around the side. The middle of the form has a panel on it, and a series of other controls drawn onto that panel. The panel and all the controls on it use XNA to draw themselves, but they are derived from Windows.Forms.Control.
I almost certainly got this code from a tutorial about 10 years back, and I’m not sure I could find it again. Still, the code didn’t change except for one line, and that line should be meaningless. The key point is that everything happens in response to the Paint event of the control, and that code is here:
Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
If Me.Visible Then
Dim beginDrawError As String = BeginDraw()
If String.IsNullOrEmpty(beginDrawError) Then
BeginDraw is very simple, as it checks to see that the graphicsDevice is in good shape, and if it is, it sets the ViewPort to the size of the client area of the control being drawn.
EndDraw is just a call to GraphicsDevice.Present. XNA 4.0 had three overloads of this method, while OpenGame has only one with no arguments. That is the only difference between my old XNA code and the OpenGame code. I had this line:
mGDeviceService.GraphicsDevice.Present(srcRect, Nothing, Me.Handle)
Where the rectangle is just the same viewport rectangle set in BeginDraw. It seems like this overload is unnecessary, because the GraphicsDevice already has the rectangle and the handle.
What is happening, though, is that various textures are being drawn onto the screen in various places, with most of the screen being white. Because each control has a series of regions within it that show tooltips, I can move the mouse around the screen and see that the controls are all being sized and positioned correctly, it is just that the drawing is…well, a mess that I can’t quite explain. The drawing is mostly absent, and what is there seems to be nearly randomly selected from the textures I have loaded.
So, the way control drawing works, is that, the panel gets invalidated, which causes all the child controls to invalidate. The Paint event is raised first for the panel, then for the child controls. I can see that this is happening, because I can see the sequence of Paint events being raised.
As for the Draw method. None of those were changed when I moved from XNA to MonoGame, so I suspect that this has something to do with the setup code, and not the code in the Draw routines, which position and compose SpriteBatch objects.
I fear that I have posted an incomplete question, but I don’t have enough experience with this to be certain as to what is relevant and what is not.
A couple additional points:
All the controls aside from the panel are dynamically loaded plugins.
The panel, the MonoGame base classes, and the control plugins are all FW4.7.2. The main program that loads all these things is currently FW 4.0.
Hope to get this sorted.