protected override void OnCreateControl()
        {
            if (!DesignMode)
            {
                graphicsDeviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height);
                gameServiceContainer.AddService(typeof(IGraphicsDeviceService), graphicsDeviceService);
                gameServiceContainer.AddService(typeof(ISystemServices), this);
                Initialize();
            }

            base.OnCreateControl();
        }
 public static GraphicsDeviceService AddRef(IntPtr windowHandle, int width, int height)
 {
     if (Interlocked.Increment(ref referenceCount) == 1)
         instance = new GraphicsDeviceService(windowHandle, width, height);
     return instance;
 }
        protected override void Dispose(bool disposing)
        {
            if (graphicsDeviceService != null)
            {
                gameServiceContainer.RemoveService(typeof(IGraphicsDeviceService));
                graphicsDeviceService.Release(disposing);
                graphicsDeviceService = null;
            }

            base.Dispose(disposing);
        }