110,536
社区成员
发帖
与我相关
我的任务
分享
// 继承按钮类
public partial class MyBtn : Button
{
/// <summary>
/// 构造
/// </summary>
public MyBtn()
{
InitializeComponent();
// 添加一个单机事件
this.Click += new EventHandler(MyBtn_Click);
}
/// <summary>
/// 此事件会在用户点击之前执行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyBtn_Click(object sender, EventArgs e)
{
this.Enabled = false;
}
/// <summary>
/// 重写按钮事件,用户处理完成后,恢复按钮
/// </summary>
/// <param name="e"></param>
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
this.Enabled = true;
}
}
public class MyButtonBase : System.Windows.Forms.Control,IButtonControl
or
public class MyButtonBase : System.Windows.Forms.ButtonBase,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
// 继承按钮类
public partial class MyBtn : Button
{
/// <summary>
/// 构造
/// </summary>
public MyBtn()
{
InitializeComponent();
// 添加一个单机事件
this.Click += new EventHandler(MyBtn_Click);
}
/// <summary>
/// 此事件会在用户点击之前执行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyBtn_Click(object sender, EventArgs e)
{
this.Enabled = false;
}
/// <summary>
/// 重写按钮事件,用户处理完成后,恢复按钮
/// </summary>
/// <param name="e"></param>
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
this.Enabled = true;
}
}
}
[code=C#]
namespace WindowsFormsApplication1
{
partial class MyBtn
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}