Reputation: 4323
I'm having a problem generating a certain path for a slightly modified round-corner rectangle. Here is the code I am using for generating the round rectangle:
public static System.Drawing.Drawing2D.GraphicsPath RoundedRectangle(Rectangle r, int d)
{
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
gp.AddArc(r.X, r.Y, d, d, 180, 90);
gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90);
gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90);
gp.AddLine(r.X, r.Y + r.Height - d, r.X, r.Y + d / 2);
return gp;
}
Now I need to generate something like this:
What would be the best approach to achieve this? Maybe by erasing the left border and then adding a right triangle somehow?
Any help is appreciated, thanks!
Upvotes: 4
Views: 903
Reputation: 23
Look at This will help you.
public void DrawRoundRect(Graphics g, Pen p, float x, float y, float width, float height, float radius)
{
GraphicsPath gp = new GraphicsPath();
gp.AddLine(x + radius, y, x + width - (radius * 2), y); // Line
gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90); // Corner
gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2)); // Line
gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90); // Corner
gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height); // Line
gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90); // Corner
gp.AddLine(x, y + height - (radius * 2), x, y + radius); // Line
gp.AddArc(x, y, radius * 2, radius * 2, 180, 90); // Corner
gp.CloseFigure();
g.DrawPath(p, gp);
gp.Dispose();
}
Upvotes: 1