• winform 自定义控件圆按钮插件


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace WGMF.TMS.CLIENT.ClientUI
    {
    public partial class RoundButton : Button
    {
    private int radius;//半径

    //圆形按钮的半径属性
    [CategoryAttribute("布局"), BrowsableAttribute(true), ReadOnlyAttribute(false)]
    public int Radius
    {
    set
    {
    radius = value;
    this.Height = this.Width = Radius;
    }
    get
    {
    return radius;
    }
    }

    private Image imageEnter;
    [CategoryAttribute("外观"), BrowsableAttribute(true), ReadOnlyAttribute(false)]
    public Image ImageEnter
    {
    set
    {
    imageEnter = value;
    }
    get
    {
    return imageEnter;
    }
    }

    private Image imageNormal;
    [CategoryAttribute("外观"), BrowsableAttribute(true), ReadOnlyAttribute(false)]
    public Image ImageNormal
    {
    set
    {
    imageNormal = value;
    BackgroundImage = imageNormal;
    }
    get
    {
    return imageNormal;
    }
    }

    //以下代码用于在VS中隐藏BackgroundImage属性,使得只能通过Diameter设置Height和Width
    [BrowsableAttribute(false)]
    public new Image BackgroundImage
    {
    get
    {
    return base.BackgroundImage;
    }
    set
    {
    base.BackgroundImage = value;

    }
    }

    //以下代码用于在VS中隐藏Size属性,使得只能通过Diameter设置Height和Width
    [BrowsableAttribute(false)]
    public new Size Size
    {
    get
    {
    return base.Size;
    }
    set
    {
    base.Size = value;

    }
    }

    public RoundButton()
    {
    Radius = 64;
    this.Height = this.Width = Radius;
    this.FlatStyle = FlatStyle.Flat;
    this.FlatAppearance.BorderSize = 0;
    this.BackgroundImage = imageEnter;
    this.BackgroundImageLayout = ImageLayout.Stretch;
    }

    //重写OnPaint
    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
    base.OnPaint(e);
    System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
    path.AddEllipse(0, 0, Radius, Radius);
    this.Region = new Region(path);
    }

    //重写OnMouseEnter
    //protected override void OnMouseEnter(EventArgs e)
    //{
    // Graphics g = this.CreateGraphics();
    // g.DrawEllipse(new Pen(Color.Blue), 0, 0, this.Width, this.Height);
    // g.Dispose();
    //}

    //重写OnSizeChanged
    protected override void OnSizeChanged(EventArgs e)
    {
    base.OnSizeChanged(e);
    if(Height != Radius)
    {
    Radius = Width = Height;
    }
    else if(Width != Radius)
    {
    Radius = Height = Width;
    }

    }

    //重写OnMouseEnter
    protected override void OnMouseEnter(EventArgs e)
    {
    base.OnMouseEnter(e);
    BackgroundImage = ImageEnter;
    }

    //重写OnMouseLeave
    protected override void OnMouseLeave(EventArgs e)
    {
    base.OnMouseLeave(e);
    BackgroundImage = ImageNormal;
    }

    }
    }

  • 相关阅读:
    通过反射将一个java对象的属性值转换为一个Map
    反射中的 Method 的 getReadMethod 与 getWriteMethod 使用 【获取一个对象的所有属性字段名称和其对应的值】
    maven项目无法导入Oracle的jdbc连接jar包【我】
    史上最全最详细JNDI数据源配置说明
    启动eclipse导致Tomcat的配置文件重置
    各种集合key,value能否为null
    CentOS系统使用yum安装配置MariaDB数据库
    Unity导出webPlayer并且部署到IIS
    unity web项目发布服务器Data file is corrupt (not a Unity W
    Unity3d Web Player 的server端联网配置
  • 原文地址:https://www.cnblogs.com/chengyihardworking/p/12759766.html
Copyright © 2020-2023  润新知