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);
            }
    

      

  • 相关阅读:
    Shortest path of the king
    二分查找c++简单模板
    2017广东工业大学程序设竞赛B题占点游戏
    2017广东工业大学程序设竞赛C题爬楼梯
    2017广东工业大学程序设竞赛E题(倒水)
    p1250 种树 贪心
    P1248 加工生产调度 贪心
    P1209 [USACO1.3]修理牛棚 Barn Repair 贪心
    P1607 [USACO09FEB]庙会班车Fair Shuttle 贪心
    P2602 [ZJOI2010]数字计数 数位dp
  • 原文地址:https://www.cnblogs.com/yaosj/p/10490030.html
Copyright © 2011-2022 走看看