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

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

  • 相关阅读:
    如何使用 IDEA 向 Github 上推送和拉取代码
    CST时间和GMT时间注意事项
    CST时间GMT时间转换
    MultipartFile转InputStream
    Java中InputStream和String之间的转化
    Fastjson 之 Json 对象、Json 字符串、Java 对象之间的转换
    Git 撤销修改
    Springboot 配置文件之 Yaml
    IDEA 快速搭建一个 Springboot 应用
    ZooKeeper 安装
  • 原文地址:https://www.cnblogs.com/anbylau2130/p/3160981.html
Copyright © 2011-2022 走看看