其他分享
首页 > 其他分享> > winform GDI基础(二)画带圆角的矩形框

winform GDI基础(二)画带圆角的矩形框

作者:互联网

  private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.SmoothingMode = SmoothingMode.HighQuality;//去掉锯齿
            g.CompositingQuality = CompositingQuality.HighQuality;//合成图像的质量
            g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;//去掉文字的锯齿
            System.Drawing.Pen p = new System.Drawing.Pen(Color.FromArgb(255, 146, 126, 102), 2);

            drawRoundedRect(g, p, 20, 20, 200, 200, 20);
        }

        /// <summary>
        /// 带圆角矩形
        /// </summary>
        /// <param name="radius">圆角半径</param>
        private void drawRoundedRect(Graphics g, System.Drawing.Pen pen, int x, int y, int width, int height, int radius)
        {
            //去掉圆角的锯齿
            g.SmoothingMode = SmoothingMode.HighQuality;

            //上
            g.DrawLine(pen, new PointF(x + radius, y), new PointF(x + width - radius, y));
            //下
            g.DrawLine(pen, new PointF(x + radius, y + height), new PointF(x + width - radius, y + height));
            //左
            g.DrawLine(pen, new PointF(x, y + radius), new PointF(x, y + height - radius));
            //右
            g.DrawLine(pen, new PointF(x + width, y + radius), new PointF(x + width, y + height - radius));

            //左上角
            g.DrawArc(pen, new Rectangle(x, y, radius * 2, radius * 2), 180, 90);
            //右上角
            g.DrawArc(pen, new Rectangle(x + width - radius * 2, y, radius * 2, radius * 2), 270, 90);
            //左下角
            g.DrawArc(pen, new Rectangle(x, y + height - radius * 2, radius * 2, radius * 2), 90, 90);
            //右下角
            g.DrawArc(pen, new Rectangle(x + width - radius * 2, y + height - radius * 2, radius * 2, radius * 2), 0, 90);
        }

  

标签:PointF,矩形框,height,width,pen,radius,画带,new,GDI
来源: https://www.cnblogs.com/yaosj/p/10490030.html