zoukankan      html  css  js  c++  java
  • 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);
            }
    

      

  • 相关阅读:
    LeetCode 275. H-Index II
    LeetCode 274. H-Index
    LeetCode Gray Code
    LeetCode 260. Single Number III
    LeetCode Word Pattern
    LeetCode Nim Game
    LeetCode 128. Longest Consecutive Sequence
    LeetCode 208. Implement Trie (Prefix Tree)
    LeetCode 130. Surrounded Regions
    LeetCode 200. Number of Islands
  • 原文地址:https://www.cnblogs.com/yaosj/p/10490030.html
Copyright © 2011-2022 走看看