zoukankan      html  css  js  c++  java
  • 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);
            }
    
        }
    }
    View Code

    做硬件测试软件,做了个点击变换颜色的控件

  • 相关阅读:
    数组排序 -- 冒泡排序
    数组自带的函数(方法)
    京东官网轮播图的实现
    鼠标单击元素输出对应元素的索引号
    JavaScript中获取HTML元素的方式
    JavaScript数组的2种定义方式
    this关键字
    JavaScript中对象的3种定义方式
    Hadoop完整搭建过程(三):完全分布模式(虚拟机)
    Hadoop完整搭建过程(二):伪分布模式
  • 原文地址:https://www.cnblogs.com/anbylau2130/p/3160981.html
Copyright © 2011-2022 走看看