string BeginDraw()
{
// If we have no graphics device, we must be running in the designer.
if (this.graphicsDeviceService == null)
{
return Text + "\n\n" + GetType();
}
// Make sure the graphics device is big enough, and is not lost.
string deviceResetError = this.HandleDeviceReset();
if (!string.IsNullOrEmpty(deviceResetError))
{
return deviceResetError;
}
// Many GraphicsDeviceControl instances can be sharing the same
// GraphicsDevice. The device backbuffer will be resized to fit the
// largest of these controls. But what if we are currently drawing
// a smaller control? To avoid unwanted stretching, we set the
// viewport to only use the top left portion of the full backbuffer.
var viewport = new Viewport
{
X = 0,
Y = 0,
Width = ClientSize.Width,
Height = ClientSize.Height,
MinDepth = 0,
MaxDepth = 1
};
this.GraphicsDevice.Viewport = viewport;
return null;
}