winfrom 圓角panel

來源:互聯網
上載者:User

標籤:des   style   class   blog   code   tar   

首先後台添加命名空間

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

 

註:以上資訊我也是通過查資料然後總結的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.