btn控件
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace ImageControls { public partial class ButtonEx : Control { public ButtonEx() { InitializeComponent(); } /// <summary> /// 控件初始化 /// </summary> private void InitializeComponent() { _BorderColor = Color.Black; _FillColor = Color.Red; } #region 字段 private Color _BorderColor; private Color _FillColor; #endregion #region 控件属性 [DefaultValue("Black"), Description("边框颜色"), Category("Appearance")] public Color BorderColor { get { // Insert code here. return _BorderColor; } set { _BorderColor = value; this.Invalidate(); } } [DefaultValue("Red"), Description("填充颜色"), Category("Appearance")] public Color FillColor { get { return _FillColor; } set { _FillColor = value; this.Invalidate(); } } #endregion protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); DrawCircle(pe, 1, _FillColor); } /// <summary> /// 如果x为0表示空心圆,如果为1表示实心圆 /// </summary> /// <param name="pe"></param> /// <param name="x"></param> private void DrawCircle(PaintEventArgs pe,int x,Color brucolor) { //定义刷子,用于填充圆的颜色 Brush brsh = new SolidBrush(brucolor); //定义笔 Brush penbrsh = new SolidBrush(_BorderColor); Pen pen = new Pen(penbrsh,2); //定义矩形 Rectangle rec = new Rectangle(); rec.X = 7; rec.Y = 7; rec.Width = this.Width - 15; rec.Height = this.Height - 15; if (x == 0) pe.Graphics.DrawEllipse(pen, rec); //画空心,黑边框的圆 else { //画实心,黑边框的圆 pe.Graphics.FillEllipse(brsh, rec); pe.Graphics.DrawEllipse(pen, rec); } } private System.ComponentModel.Container components = null; protected override void Dispose(bool disposing) { if (disposing) { if (components != null) components.Dispose(); } base.Dispose(disposing); } } }
做硬件测试软件,做了个点击变换颜色的控件