日期:2014-05-18  浏览次数:20779 次

C# 我自己定义了一个按钮然后在WINFORM中画了10个出来现在想他们执行统一的CLICK
C# 我自己定义了一个按钮然后在WINFORM中画了10个出来现在想他们执行统一的CLICK我该怎么弄呢?

比如说我想无论点哪个我自定义的按钮都执行Messagebox.show("aaa")

类的定义为:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace zhenbar
{
  public partial class bArea : System.Windows.Forms.CheckBox
  {
  public bArea()
  : base()
  {
  this.Appearance = System.Windows.Forms.Appearance.Button;
  this.Size = new System.Drawing.Size(90, 40);
  this.AutoSize = false;
  this.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  this.Text = "";
  this.fid = "0";
  this.fcount = "0";
  this.fMaxRow = "0";
  this.fNowRow = "0";
  }
   
  /// <summary
  /// 数据库中的字段名
  /// </summary>
  public string fid { get; set; }
  public string fcount { get; set; }
  public string fMaxRow { get; set; }
  public string fNowRow { get; set; }
  }
}


------解决方案--------------------
button1.click=new eventhandler(btn_clickdeal);
button2.click=new eventhandler(btn_clickdeal);
............
buttonN.click=new eventhandler(btn_clickdeal);
------解决方案--------------------
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("这里是button2的方法");
}

在onlode事件里面调用下面的方法
private void OnloadButton3()
{
this.button3.Click += new System.EventHandler(button2_Click);
}
这样你就可以在代码里手动给button3添加事件 并且调用了button2的chick事件的方法
这样还有什么疑问