Resolve how to draw the corner of the control's border as an arc in C

  • 2020-05-17 06:15:11
  • OfStack


private void Draw(Graphics graphics, Control control)
        {
            float X = float.Parse(control.Width.ToString()) - 1;
            float Y = float.Parse(control.Height.ToString()) - 1;
            PointF[] pointfs = {
                new PointF(2,     0),
                new PointF(X-2,   0),
                new PointF(X-1,   1),
                new PointF(X,     2),
                new PointF(X,     Y-2),
                new PointF(X-1,   Y-1),
                new PointF(X-2,   Y),
                new PointF(2,     Y),
                new PointF(1,     Y-1),
                new PointF(0,     Y-2),
                new PointF(0,     2),
                new PointF(1,     1)
                };
            GraphicsPath path = new GraphicsPath();
            path.AddLines(pointfs);
            Pen pen = new Pen(Color.FromArgb(150, Color.Blue), 1);
            pen.DashStyle = DashStyle.Solid;
            graphics.DrawPath(pen, path);
        }

Paint+= event name, and then the above functions are passed as parameters, such as: Draw(e.Graphics, this.control);


Related articles: