title: Creating RenderForm (slimdx) outside main Program
body: <p>I am stuck at the very beginning of slim DX.. </p>
  
  <p>My MdiParent name is view</p>
  
  <p>What I want to do is create a <code>RenderForm()</code> or simular, Inside of a Form Application as MdiChild, the <code>RenderForm()</code> is a form where we display DirectX.
  The reason for this is to be able to create Menubars and buttons etc Inside the Parent form.
  I have tryed to create a new form for the rendering but it doesn't work very well with <code>MessagePump()</code>. The whole application hangs. The reason for this might be a endless loop. 
  One other method I have tryed is to create a RenderForm inside the view by Calling a function from Main Program This doesn't work very well either since the Main Program aint executing any code after <pre></p>
  
  <pre><code>Application.EnableVisualStyles();
  Application.Run(new view()); 
  </code></pre>
  
  <p></pre>
  I have tryed a ton of diffrent methods I came up with but with no success. I have googled for hours without result. </p>
  
  <p>The code I am trying to modify is copyed from the SlimDX tutorial 2:</p>
  
  <pre>
  
      using System.Windows.Forms;
      using SlimDX;
      using SlimDX.Direct3D11;
      using SlimDX.DXGI;
      using SlimDX.Windows;
      using Device = SlimDX.Direct3D11.Device;
      using Resource = SlimDX.Direct3D11.Resource;
  
      namespace DeviceCreation
      {
          static class Program
          {
              static void Main()
              {
                  var form = new RenderForm("Tutorial 2: Device Creation");
                  var description = new SwapChainDescription()
                  {
                      BufferCount = 1,
                      Usage = Usage.RenderTargetOutput,
                      OutputHandle = form.Handle,
                      IsWindowed = true,
                      ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                      SampleDescription = new SampleDescription(1, 0),
                      Flags = SwapChainFlags.AllowModeSwitch,
                      SwapEffect = SwapEffect.Discard
                  };
  
                  Device device;
                  SwapChain swapChain;
                  Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, out device, out swapChain);
  
                  // create a view of our render target, which is the backbuffer of the swap chain we just created
                  RenderTargetView renderTarget;
                  using (var resource = Resource.FromSwapChain(swapChain, 0))
                      renderTarget = new RenderTargetView(device, resource);
  
                  // setting a viewport is required if you want to actually see anything
                  var context = device.ImmediateContext;
                  var viewport = new Viewport(0.0f, 0.0f, form.ClientSize.Width, form.ClientSize.Height);
                  context.OutputMerger.SetTargets(renderTarget);
                  context.Rasterizer.SetViewports(viewport);
  
                  // prevent DXGI handling of alt+enter, which doesn't work properly with Winforms
                  using (var factory = swapChain.GetParent())
                      factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAltEnter);
  
                  // handle alt+enter ourselves
                  form.KeyDown += (o, e) =>
                  {
                      if (e.Alt && e.KeyCode == Keys.Enter)
                          swapChain.IsFullScreen = !swapChain.IsFullScreen;
                  };
  
                  MessagePump.Run(form, () =>
                  {
                      // clear the render target to a soothing blue
                      context.ClearRenderTargetView(renderTarget, new Color4(0.5f, 0.5f, 1.0f));
                      swapChain.Present(0, PresentFlags.None);
                  });
  
                  // clean up all resources
                  // anything we missed will show up in the debug output
                  renderTarget.Dispose();
                  swapChain.Dispose();
                  device.Dispose();
              }
          }
      }
  
  
  </pre>
  
  <p>I have never succeeded to place the  MessagePump() outside the Main Program.</p>