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;

e.Graphics.DrawEllipse(pen, rect);
}
}

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.