BLOG.CSHARPHELPER.COM: Draw an ellipse that sort of looks like a button in C#
Draw an ellipse that sort of looks like a button in C#
This example uses two LinearGradientBrushes to draw an ellipse that has a sort of three-dimensional button-like appearance. The key is to outline the ellipse and fill it with brushes whose gradients point in opposite directions. The following code fills the ellipse with a brush that changes from lime to dark green in the direction 225 degrees. It then outlines it with a brush that flows from lime to dark green in the opposite direction: 45 degrees.
// Fill the ellipse. using (LinearGradientBrush br = new LinearGradientBrush(rect, Color.Lime, Color.DarkGreen, 225f)) { e.Graphics.FillEllipse(br, rect); }
// Outline the ellipse. using (LinearGradientBrush br = new LinearGradientBrush(rect, Color.Lime, Color.DarkGreen, 45f)) { using (Pen pen = new Pen(br, 20f)) { rect.X += 10; rect.Y += 10; rect.Width -= 20; rect.Height -= 20;
Comments