按钮动画控件----------WinForm控件开发系列

  public partial class ButtonExt : Button
  {
    private AnimationTimer _Animation;
    /// <summary>
    /// 动画组件对象
    /// </summary>
    [Description("动画组件对象")]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public AnimationTimer Animation
    {
      get { return _Animation; }
      set { _Animation = value; }
    }

    protected override Size DefaultSize
    {
      get
      {
        return new Size(100, 40);
      }
    }
    public ButtonExt()
    {
      InitializeComponent();
      this.BackColor = System.Drawing.Color.OliveDrab;
      this.FlatAppearance.BorderSize = 0;
      this.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
      this.ForeColor = System.Drawing.Color.White;

      this._Animation = new AnimationTimer(this, new AnimationOptions());
      this.Animation.AnimationIng += new AnimationTimer.AnimationHandel(Animation_AnimationIng);
    }

    protected void Animation_AnimationIng(object sender, AnimationEventArgs e)
    {
      ButtonExt control = (ButtonExt)sender;
      control.Width = (int)((double)control.original_w + e.Transform * e.progressTime);
      control.Height = (int)((double)control.original_h + e.Transform * e.progressTime);
      int x = (int)((this.original_w - control.Width) / 2.0);
      int y = (int)((this.original_h - control.Height) / 2.0);
      control.Location = new Point((int)this.original_x + x, (int)this.original_y + y);
    }

    protected override void OnMouseEnter(EventArgs e)
    {
      base.OnMouseEnter(e);

      this.loadOriginal(this.original_isload);
      this._Animation.AT = AnimationType.ElasticOut;
      this._Animation.Start(true, this._Animation.UsedTime);
    }

    protected override void OnMouseLeave(EventArgs e)
    {
      base.OnMouseLeave(e);
      this._Animation.AT = AnimationType.BackIn;
      this._Animation.Start(false, this._Animation.UsedTime);
    }

    private bool original_isload = false;
    private double original_w = 0.0;// 动画对象开始制定属性原始值
    private double original_h = 0.0;// 动画对象开始制定属性原始值
    private int original_x = 0;// 动画对象开始制定属性原始值
    private int original_y = 0;// 动画对象开始制定属性原始值
    private void loadOriginal(bool _isload)
    {
      if (!_isload)
      {
        this.original_w = this.Width;
        this.original_h = this.Height;
        this.original_x = this.Location.X;
        this.original_y = this.Location.Y;
        this.original_isload = true;
      }

    }

    /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
    protected override void Dispose(bool disposing)
    {
      if (disposing && (components != null))
      {
        components.Dispose();
        if (this._Animation != null)
        {
          this._Animation.Dispose();
        }
      }
      base.Dispose(disposing);
    }
  }

源码下载:按钮动画控件.zip

原文地址:https://www.cnblogs.com/tlmbem/p/11204624.html

时间: 2024-10-05 04:55:01

按钮动画控件----------WinForm控件开发系列的相关文章

TabPanel美化控件----------WinForm控件开发系列

/// <summary> /// TabControl /// </summary> [ToolboxItem(true)] [Description("TabControl")] public partial class TabControlExt : TabControl { #region private AnimationTimer animation; /// <summary> /// 动画组件对象 /// </summary&g

加载等待控件----------WinForm控件开发系列

/// <summary> /// 加载进度控件 /// </summary> [ToolboxItem(true)] [Description("加载进度控件")] [DefaultProperty("Active")] public partial class LoadProgressExt : Control { #region 属性 private LoadProgressType progressType = LoadProgres

走马灯图片轮播控件----------WinForm控件开发系列

/// <summary> /// 走马灯图片轮播控件 /// </summary> [ToolboxItem(true)] [DefaultProperty("Images")] [Description("走马灯图片轮播控件")] public partial class ImageCarouselExt : Control { #region private bool barShow = true; /// <summary>

GDI不规则圆弧菜单控件----------WinForm控件开发系列

/// <summary> /// 圆弧菜单控件 /// </summary> [ToolboxItem(true)] [DefaultProperty("Items")] [DefaultEvent("RadianMenuItemClick")] [Description("圆弧菜单控件")] public partial class RadianMenuExt : Control { public delegate v

水波纹进度控件----------WinForm控件开发系列

/// <summary> /// 水波纹进度控件 /// </summary> [ToolboxItem(true)] [DefaultProperty("Value")] [DefaultEvent("ValueChanged")] [Description("水波纹进度控件")] public partial class WaveProgressExt : Control { public delegate void

雷达分析图控件----------WinForm控件开发系列

/// <summary> /// 雷达分析图控件 /// </summary> [ToolboxItem(true)] [DefaultProperty("ChartLineItems")] [Description("雷达分析图控件")] public partial class RadarChartExt : Control { #region private ChartTypes chartType = ChartTypes.Circ

数字时间控件----------WinForm控件开发系列

/// <summary> /// 数字时间控件 /// </summary> [ToolboxItem(true)] [DefaultProperty("Value")] [DefaultEvent("ValueChanged")] [Description("数字时间控件")] public partial class TimeExt : Control { public delegate void EventHand

MAC鱼眼效果菜单控件----------WinForm控件开发系列

/// <summary> /// 鱼眼菜单 /// </summary> [DefaultProperty("Items")] [DefaultEvent("FisheyeItemClick")] [Description("鱼眼菜单")] public partial class FisheyeBarExt : Control { public delegate void EventHandler(object sen

雷达扫描控件----------WinForm控件开发系列

/// <summary> /// 雷达扫描控件 /// </summary> [ToolboxItem(true)] [DefaultProperty("Items")] [Description("雷达扫描控件")] public partial class RadarExt : Control { #region private Color areaColor = Color.LawnGreen; /// <summary>