protected override void OnPaintBackground (PaintEventArgs e)
{
base.OnPaintBackground (e);
var rectangleToPaint = ClientRectangle;
if (rectangleToPaint.Width <= 0 || rectangleToPaint.Height <= 0)
return; // can't draw anything, and will crash if we try
var beginColor = Color.FromArgb(0x58, 0x80, 0xd0);
var endColor = Color.FromArgb(0x08, 0x40, 0x98);
using (var brush = new LinearGradientBrush(rectangleToPaint, beginColor, endColor,
LinearGradientMode.Vertical))
{
e.Graphics.FillRectangle(brush, rectangleToPaint);
}
// Draw a background image if we have one set.
// This code assumes it is always centered.
Graphics g = e.Graphics;
var backgroundImage = this.BackgroundImage;
if (backgroundImage != null)
{
var drawRect = new Rectangle();
drawRect.Location = new Point(ClientSize.Width / 2 - backgroundImage.Width /2,
ClientSize.Height /2 - backgroundImage.Height /2);
drawRect.Size = backgroundImage.Size;
g.DrawImage( backgroundImage, drawRect);
}
}