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
        }
    }
    你应该了解真相,真相使你自由!
  • 相关阅读:
    dmesg
    [转]df命令
    [转]linux /proc/cpuinfo 文件分析
    awk
    sed
    [转]进程间通信
    Bootstrap 树形列表与右键菜单
    Maven国内仓库
    《深入剖析Tomcat》源码
    Spring in Action学习笔记(2)
  • 原文地址:https://www.cnblogs.com/Hooper_he/p/9636812.html
Copyright © 2011-2022 走看看