BLOG.CSHARPHELPER.COM: Draw numbered circles that look like buttons and save them into files in C#
Draw numbered circles that look like buttons and save them into files in C#
This example is very similar to the previous one Draw numbered circles and save them into files in C# except it draws numbered circles slightly differently. The following code shows how the program draws the circles' backgrounds.
// Fill the background.
const int margin = 2;
int rect_width = width - 2 * margin;
if (rect_width < 1) rect_width = 1;
Rectangle outer_rect = new Rectangle(margin, margin,
rect_width, rect_width);
using (LinearGradientBrush bg_brush = new LinearGradientBrush(
outer_rect, Color.White, bg_color, LinearGradientMode.BackwardDiagonal))
{
gr.FillEllipse(bg_brush, outer_rect);
}
rect_width = width - 2 * (margin + border_width);
if (rect_width < 1) rect_width = 1;
Rectangle inner_rect = new Rectangle(
margin + border_width, margin + border_width,
rect_width, rect_width);
using (LinearGradientBrush bg_brush = new LinearGradientBrush(
inner_rect, bg_color, Color.White, LinearGradientMode.BackwardDiagonal))
{
gr.FillEllipse(bg_brush, inner_rect);
}
The code first makes a rectangle that includes the bitmap's area minus a 2-pixel margin around the edges. It uses that rectangle to fill the background with a circle that shades from white in the upper right to a background color on the lower left.
Next the code repeats the same steps with two changes. First it reduces the size of the rectangle to make a smaller circle so the space between the two looks like a shaded border. Second it reverses the shading to the inner circles shades from white in the lower left corner to the background color in the upper right.
The result appears to be a button with an inset surface as shown in the picture. (See the previous example for additional details.)
Comments