自定义控件绘制画圆
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 } }
你应该了解真相,真相使你自由!