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
        }
    }
    你应该了解真相,真相使你自由!
  • 相关阅读:
    Cassandra
    【CISCO强烈推荐】生成树 《路由协议》 卷一二 拥塞:网络延迟 阻塞:进程中 MTU QS:服务质量 OSPF RIP ISIS BGP 生成树 《路由协议》 卷一二
    m*n matrix min rank square matrix
    Moving Computation is Cheaper than Moving Data
    SASL mechanism
    一阶 斜率 二阶 原函数的粗糙度 roughness
    Linux 虚拟内存盘
    Bloom Filters
    R Tree
    释放内存
  • 原文地址:https://www.cnblogs.com/Hooper_he/p/9636812.html
Copyright © 2011-2022 走看看