zoukankan      html  css  js  c++  java
  • Form扁平化设计之 Panel样式重绘-圆角(还未实现)

        /// <summary>
        /// 重写Panel-还未实现圆角功能
        /// </summary>
        public class RoundPanel : Panel
        {
            private int mMatrixRound = 8;
            private Color mBack;
    
            public Color Back
            {
                get { return mBack; }
                set
                {
                    if (value == null)
                    {
                        mBack = Control.DefaultBackColor;
                    }
                    else
                    {
                        mBack = value;
                    }
                    base.Refresh();
                }
            }
    
            public int MatrixRound
            {
                get { return mMatrixRound; }
                set
                {
                    mMatrixRound = value;
                    base.Refresh();
                }
            }
    
            private GraphicsPath CreateRound(Rectangle rect, int radius)
            {
                GraphicsPath roundRect = new GraphicsPath();
                //顶端 
                roundRect.AddLine(rect.Left + radius - 1, rect.Top - 1, rect.Right - radius, rect.Top - 1);
                //右上角 
                roundRect.AddArc(rect.Right - radius, rect.Top - 1, radius, radius, 270, 90);
                //右边 
                roundRect.AddLine(rect.Right, rect.Top + radius, rect.Right, rect.Bottom - radius);
                //右下角
    
                roundRect.AddArc(rect.Right - radius, rect.Bottom - radius, radius, radius, 0, 90);
                //底边 
                roundRect.AddLine(rect.Right - radius, rect.Bottom, rect.Left + radius, rect.Bottom);
                //左下角 
                roundRect.AddArc(rect.Left - 1, rect.Bottom - radius, radius, radius, 90, 90);
                //左边 
                roundRect.AddLine(rect.Left - 1, rect.Top + radius, rect.Left - 1, rect.Bottom - radius);
                //左上角 
                roundRect.AddArc(rect.Left - 1, rect.Top - 1, radius, radius, 180, 90);
                return roundRect;
            }
    
            protected override void OnPaint(PaintEventArgs e)
            {
                int width = base.Width - base.Margin.Left - base.Margin.Right;
                int height = base.Height - base.Margin.Top - base.Margin.Bottom;
                Rectangle rec = new Rectangle(base.Margin.Left, base.Margin.Top, width, height);
                GraphicsPath round = CreateRound(rec, mMatrixRound);
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                e.Graphics.FillPath((Brush)(new SolidBrush(mBack)), round);
            }
    
            protected override void OnResize(EventArgs eventargs)
            {
                base.Refresh();
            }
        }
    365个夜晚,我希望做到两天更一篇博客。加油,小白!
  • 相关阅读:
    javascript Math.random()随机数函数
    asp.net 前台获取后台c#代码信息
    关于C#网站一般处理程序(ashx)中session的问题
    怎样才能在一般处理文件中创建新的Session和访问已经存在的Session?
    使用SqlParameter向数据库中插入数据
    C#串口编程学习简单实例
    认识nodejs
    01.Javascript中的接口Interface [转载]
    动态添加脚本,并触发回调函数 初步实现按需加载
    JS正则表达式 收藏
  • 原文地址:https://www.cnblogs.com/qq2806933146xiaobai/p/15132647.html
Copyright © 2011-2022 走看看