I added some winforms controls into my XNA game so I can have a on-the-fly level editor. The game screen runs internally at 640x480 and it's render target is drawn into a window that's at 800x600 that has some controls put in it.
The problem is the game starts running at less than 60 frames a second, sometimes even going down to 40 frames a second. It doesn't do this in any other resolution without winforms, not even at 1280 x 960 full screen.
The method I used is this:
Form frm = Control.FromHandle(this.Window.Handle) as Form;
This creates a form from your game's window handle. How handy.
and then adding controls and stuff like so:
// setup the panel control
this.panel1.Dock = DockStyle.Right;
this.panel1.Width = 160;
// create a exit button and add it to the panel
Button button = new Button();
button.Location = new System.Drawing.Point(2, 10);
button.Text = "Exit";
button.Click += (sender, e) => { this.Exit(); };
this.panel1.Controls.Add(button);
// add the panel to the game window form
frm.Controls.Add(this.panel1);
You also have to add/change the references/dependencies like so in the top of the Game class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using ButtonState = Microsoft.Xna.Framework.Input.ButtonState;
using Point = System.Drawing.Point;
using Keys = Microsoft.Xna.Framework.Input.Keys;
Anyone have any clue why this would run slowly? I'm I doing something wrong? Is something in the windows message loop screwing my game up?