[C #] [XNA 3.1] How can I place two different XNA windows inside the same Windows form?

I am making a map editor for a 2D tile. I would like to place two XNA controls inside a Windows form - the first to display a map; the second is for rendering tiles. I used the code here to make an XNA management host inside a Windows form. All this works very well - so far there is only one XNA control in Windows form. But I need two - one for the card; the second is for tiles. How can I run two XNA controls inside a windows form? While googling, I came across the terms “swap chain” and “multiple viewports”, but I cannot understand them and would appreciate support.

As a note, I know that the XNA control example was designed so that even if you run 100 XNA controls, they will all use the same GraphicsDevice - in fact, all 100 XNA controls will have the same screen. I tried modifying the code to create a new GraphicsDevice for each XNA control, but the rest of the code does not work. The code is a bit long for publication, so I won’t publish it unless someone needs it to help me.

Thanks in advance.

+7
c # winforms xna
source share
3 answers

I did something similar to what you are trying to do. All you have to do is show the graphic device where you can present the “material” that you have provided. You do this by passing it a pointer to the canvas.

Here is an example form:

public class DisplayForm : Form { IntPtr canvas; Panel displaypanel; public Panel DisplayPanel { get { return displaypanel; } set { displaypanel = value; } } public IntPtr Canvas { get { return canvas; } set { canvas = value; } } public DisplayForm() { displaypanel = new Panel(); displaypanel.Dock = DockStyle.Fill; this.canvas = displaypanel.Handle; this.Controls.Add(displaypanel); } } 

Then just add this to the game class drawing call:

 graphics.GraphicsDevice.Present(displayform.Canvas); 

After you finish drawing on this DisplayForm instance, you can clear, display something else and call Present again, pointing to another canvas.

+6
source share
+2
source share

Just a thought, but have you thought about making this application your MDI application?

this way you can upload a form containing 1 xna instance several times.

Otherwise ... do what RodYan offers :)

+1
source share

All Articles