zoukankan      html  css  js  c++  java
  • 自定义控件绘制画圆

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.ComponentModel;
    
    namespace WindowsFormsApplication1
    {
        public class myButton:Panel
        {
            Control _preControl;
            Color _myBackColor;
    
            public Color MyBackColor
            {
                get { return _myBackColor; }
                set { _myBackColor = value;
                this.Invalidate();
                }
            }
            public Control PreControl
            {
                get { return _preControl; }
                set { _preControl = value;
                this.Invalidate();
                }
            }
            public myButton()
            {
                this.SetStyle(ControlStyles.AllPaintingInWmPaint |
                    ControlStyles.OptimizedDoubleBuffer |
                    ControlStyles.UserPaint|
                ControlStyles.SupportsTransparentBackColor|
                ControlStyles.ResizeRedraw, true);
                this.UpdateStyles();
                _myBackColor = Color.LightBlue;
            }
    
            protected override void OnPaint(PaintEventArgs pevent)
            {
                Graphics gp = pevent.Graphics;
                gp.SmoothingMode = SmoothingMode.AntiAlias;
                Rectangle rect=new Rectangle(0, 0, this.Width - 1, this.Height - 1);
                gp.DrawEllipse(new Pen(_myBackColor, 1),rect );
                LinearGradientBrush gb = new LinearGradientBrush(rect, Color.White, Color.Black, 0f);   //线性渐变
                gp.FillEllipse(gb, rect);     //线性渐变
                //gp.FillEllipse(new SolidBrush(_myBackColor), rect);       //单色画笔
                
            }
    
            #region 隐藏属性
            [Browsable(false)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            public override Color BackColor
            {
                get
                {
                    return base.BackColor;
                }
                
            }
    
            #endregion
        }
    }
    你应该了解真相,真相使你自由!
  • 相关阅读:
    OC中ARC forbids explicit message send of release错误
    OC中内存管理(转)
    [题解]数学期望_luogu_P1850_换教室
    [题解](单调队列)luogu_P2216_BZOJ_1047 理想的正方形
    [题解]luogu_AT1224_JOIOJI
    [题解]区间dp_luogu_P3147 262144
    [筆記]歐拉路
    [題解/狀壓dp]POJ_2411_Mondriaan's dream
    [題解]luogu_P1854 花店櫥窗佈置
    [題解]luogu_P1052 過河
  • 原文地址:https://www.cnblogs.com/Hooper_he/p/9636812.html
Copyright © 2011-2022 走看看