I'm drawing some glyphs in a WinForms application. Each glyph is defined by a graphics path, basically is a rectangle with rounder corners.
Now I fill the graphics path with a single color, but I need to fill with two colors. The following example explains what I need:
I would like to avoid creating a new GraphicsPath
because the performance of the application could be affected.
Is there any tricky option to draw the second fill color without creating a new graphics path?
Here is the code of my graphics path:
public class RoundedRectangle
{
public static GraphicsPath Create(int x, int y, int width, int height)
{
int radius = height / 2;
int xw = x + width;
int yh = y + height;
int xwr = xw - radius;
int xr = x + radius;
int r2 = radius * 2;
int xwr2 = xw - r2;
GraphicsPath p = new GraphicsPath();
p.StartFigure();
// Right arc
p.AddArc(xwr2, y, r2, r2, 270, 180);
//Bottom Edge
p.AddLine(xwr, yh, xr, yh);
// Left arc
p.AddArc(x, y, r2, r2, 90, 180);
//closing the figure adds the top Edge automatically
p.CloseFigure();
return p;
}
}