zoukankan      html  css  js  c++  java
  • c# winForm 圆角Panel

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Drawing.Drawing2D;

    namespace RoundPanel
    {
        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();
            }
        }
    }

  • 相关阅读:
    Spring AOP中文教程《转》
    VBScript 转义字符
    Spring工作原理
    Struts+Hibernate+Spring工作原理及使用理由
    SQL Server中,varchar和nvarchar如何选择?<转>
    TSQL 游标使用
    oracle 与sql server临时表 比较《转》
    Oracle查询语法大全<转>
    B/S 模式 套打 的一种实现方式<转>
    基于Web的套打方案集粹<转>
  • 原文地址:https://www.cnblogs.com/hfzsjz/p/1799062.html
Copyright © 2011-2022 走看看