zoukankan      html  css  js  c++  java
  • winfrom 圆角化

      private void Draw(Rectangle rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color)
            {
                int span = 2;
                //抗锯齿
                g.SmoothingMode = SmoothingMode.AntiAlias;
                //渐变填充
                LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(rectangle, begin_color, end_color, LinearGradientMode.Vertical);
                //画尖角
                if (cusp)
                {
                    span = 10;
                    PointF p1 = new PointF(rectangle.Width - 12, rectangle.Y + 10);
                    PointF p2 = new PointF(rectangle.Width - 12, rectangle.Y + 30);
                    PointF p3 = new PointF(rectangle.Width, rectangle.Y + 20);
                    PointF[] ptsArray = { p1, p2, p3 };
                    g.FillPolygon(myLinearGradientBrush, ptsArray);
                }
                //填充
                g.FillPath(myLinearGradientBrush, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - span, rectangle.Height - 1, _radius));
            }
            public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
            {
                //四边圆角
                GraphicsPath gp = new GraphicsPath();
                gp.AddArc(x, y, radius, radius, 180, 90);
                gp.AddArc(width - radius, y, radius, radius, 270, 90);
                gp.AddArc(width - radius, height - radius, radius, radius, 0, 90);
                gp.AddArc(x, height - radius, radius, radius, 90, 90);
                gp.CloseAllFigures();
                return gp;
            }
    
            private void panel1_Paint(object sender, PaintEventArgs e)
            {
                Draw(e.ClipRectangle, e.Graphics, 12, false, Color.FromArgb(112, 127, 154), Color.FromArgb(19, 23, 32));
                base.OnPaint(e);
                Graphics g = e.Graphics;
                g.DrawString("", new Font("微软雅黑", 9, FontStyle.Regular), new SolidBrush(Color.White), new PointF(10, 10));
    
            }

    int _radius 圆的度数

    bool cusp 画不画尖角

    Color begin_color, Color end_color 渐变色的起始和结束颜色

    private void Draw(Rectangle rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color)
            {.......}

    圆角按钮要设置

    否则4个角还有颜色。

    皆可画圆。

    转载至https://www.cnblogs.com/dachuang/p/8931795.html

  • 相关阅读:
    sql except 用法,找两个表中非共同拥有的
    ‘堆’出你的洪荒之力
    原来你是个这样的JVM
    变形词
    54题
    最大对称子数组
    java 线程之间通信以及notify与notifyAll区别。
    大型网站架构系列:消息队列
    剑指offer第10题
    & 和 && 区别
  • 原文地址:https://www.cnblogs.com/xuezhu/p/12848451.html
Copyright © 2011-2022 走看看