• winfrom 圆角panel


    首先后台添加命名空间

    using System.Drawing.Drawing2D;

    后台代码

    namespace Report.Web
    {
        public partial 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();
                }
            }
            /// <summary>圆角弧度(0为不要圆角)</summary>         
             [Browsable(true)]          //显示到属性栏
             [Description("圆角弧度(0为不要圆角)")]//属性栏 显示的注释
            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 pe)
            {
                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);
                pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                pe.Graphics.FillPath((Brush)(new SolidBrush(mBack)), round); 
            }
            protected override void OnResize(EventArgs eventargs)
            {
                base.Refresh();
            } 
        }
    }

    注:以上信息我也是通过查资料然后总结的。

  • 相关阅读:
    sdut3664顺序表应用7:最大子段和之分治递归法
    循环并行执行
    c# 计算语句执行时间
    npm install g cordovares出现异常Failed at the sharp@0.29.3 install script.
    ionic tab页再次进入不会初始化组件调用ngOnInit
    sql 分组后取第一条数据
    OOM 问题分类
    MyBatis的一级缓存和二级缓存
    SpringBoot常用注解
    Eclipse/MAT下载过慢的问题
  • 原文地址:https://www.cnblogs.com/zhaoqiangxiaoxiao/p/3786049.html
Copyright © 2020-2023  润新知