基类窗体:protected virtual void SayHello_Click(object sender, System.EventArgs e)
{
  MessageBox.Show ("Hello");
}继承窗体protected override void SayHello_Click(object sender, System.EventArgs e)
{
  MessageBox.Show ("OK");
}当点击SayHello按钮时,出现了两次“OK”提示

解决方案 »

  1.   

    deltegate看到的是一个方法,它并不关心这个方法是哪个类实现的,所以保存的是方法本身,而不是vtable中的指针,你的目的是达不到的。你可以添加一个方法来调用SayHello_Click中调用另外一个虚方法来达到你的目的。
      

  2.   

    原因找到了。
    把基类中的
     this.SayHello.Click += new System.EventHandler(this.SayHello_Click);
    注释掉就可以了。谢谢  qimini(循序渐进)
      

  3.   

    faint,可你居然说没有订阅事件?
      

  4.   

    把基类中的
     this.SayHello.Click += new System.EventHandler(this.SayHello_Click);
    注释掉就可以了。????那你在哪订阅的
      

  5.   

    把基类中的
     this.SayHello.Click += new System.EventHandler(this.SayHello_Click);
    注释掉就可以了。????那你在哪订阅的
    强烈支持    xingd(xingd)
      

  6.   

    我编了一个demo,没有出现楼主的问题啊,大家看看namespace ClickTwoDemo
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(96, 104);
    this.button1.Name = "button1";
    this.button1.TabIndex = 0;
    this.button1.Text = "button1";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.button1});
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion protected virtual void button1_Click(object sender, System.EventArgs e)
    {
    MessageBox.Show("Show Me");
    }
    } public class MyForm:Form1
    {
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new MyForm());
    } protected override void button1_Click(object sender, System.EventArgs e)
    {
    MessageBox.Show("Show Me");
    }
    }