Ho un metodo che disegna un rettangolo arrotondato con un bordo. Il bordo può essere di qualsiasi larghezza, quindi il problema che sto avendo è che il bordo si estende oltre i limiti dati quando è spesso perché è disegnato dal centro di un tracciato.Come disegnare un rettangolo arrotondato con bordo di larghezza variabile all'interno di limiti specifici
Come includere la larghezza del bordo in modo che si adatti perfettamente ai limiti specificati?
Ecco il codice che sto usando per disegnare il rettangolo arrotondato.
private void DrawRoundedRectangle(Graphics gfx, Rectangle Bounds, int CornerRadius, Pen DrawPen, Color FillColor)
{
GraphicsPath gfxPath = new GraphicsPath();
DrawPen.EndCap = DrawPen.StartCap = LineCap.Round;
gfxPath.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90);
gfxPath.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90);
gfxPath.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
gfxPath.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
gfxPath.CloseAllFigures();
gfx.FillPath(new SolidBrush(FillColor), gfxPath);
gfx.DrawPath(DrawPen, gfxPath);
}