WinForm------PanelControl控件中使用Pen类画角圆矩形方法

private void rightPanel_Paint(object sender, PaintEventArgs e)
{
    Graphics g = e.Graphics;
    Pen p = new Pen(Color.FromArgb(255,146,126,102));
    p.Width = 8;
    DrawRoundRect(g, p, 110 + nowPicture * 370, 122, 292, 200, 10);
}

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);
  
  gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90);

  gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2));

  gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90);

  gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height);

  gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90);

  gp.AddLine(X, Y + height - (radius * 2), X, Y + radius);

  gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90);

  gp.CloseFigure();

  g.DrawPath(p, gp);
  gp.Dispose();
}
原文地址:https://www.cnblogs.com/tianhengblogs/p/6101865.html