title: embedded XNA 4.0 game in WinForm is running too slow, what do I do?
body: <p>I have an embedded XNA 4.0 game in WinForm (for a level editor). The code is in this format:</p>
  
  <p>in the game class:</p>
  
  <pre><code>protected override void Initialize(){
      //initialization logic here  
      base.Initialize();
  
      SysWinForms.Form gameWindowForm(SysWinForms.Form)SysWinForms.Form.FromHandle(this.Window.Handle);
      gameWindowForm.Shown += new EventHandler(gameWindowForm_Shown);
  
      MYFORM = new Form1();
      MYFORM.HandleDestroyed += new EventHandler(myForm_HandleDestroyed);
      MYFORM.Show();
  }
  
  
  void myForm_HandleDestroyed(object sender, EventArgs e)
  {
      this.Exit();
  }
  
  void gameWindowForm_Shown(object sender, EventArgs e)
  {
       ((SysWinForms.Form)sender).Hide(); 
       //this line is important. When this line is commented the XNA + winForm windows are both shown. Also, the xna game is running in the winForm and it is running with modest speed. 
       //but when the line is not commented, than only the winForm window is shown and the xna game is shown inside it, but it is running with 0.5 frames/seconds
  }
  
  //The loadContent, unloadContent, update, and game constructor classes remain the same
  
  protected override void Draw(GameTime gameTime)
  {
       //draw logic here
       base.Draw(gameTime);
          //this is the actual trick that makes it all happen
          this.GraphicsDevice.Present(new Rectangle(controls.panel1.Location.X, controls.panel1.Location.Y, desired_Width, desired_Height), null, this.MYFORM.PanelHandle);
  }
  </code></pre>
  
  <p>in the MYFORM class:</p>
  
  <pre><code>public IntPtr PanelHandle
  {
      get
      {
          return this.panel1.IsHandleCreated ? this.panel1.Handle : IntPtr.Zero;
      }
  }
  </code></pre>
  
  <p>also there is a automatically generated:</p>
  
  <pre><code>public System.Windows.Forms.Panel panel1;
  </code></pre>
  
  <p>I will be really grateful if somebody took a look at the code, and especially at the comment in " void gameWindowForm_Shown(object sender, EventArgs e) " function. </p>
  
  <p>thx in advance</p>