C# 按钮的鼠标向下事件

C# 按钮的鼠标向下事件,c#,winforms,mouseevent,C#,Winforms,Mouseevent,在VisualStudio2008C应用程序中,我有带按钮的控件。我尝试为按钮获取MouseDown事件,该事件在按钮继承的控件类中定义。 如果我这样写: this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Button_MouseDown); 它进行编译,但未提出偶数 这同样适用于整个面板本身 this.MouseDown += new System.Windows.Forms.Mous

在VisualStudio2008C应用程序中,我有带按钮的控件。我尝试为按钮获取MouseDown事件,该事件在按钮继承的控件类中定义。 如果我这样写:

this.button1.MouseDown += 
    new System.Windows.Forms.MouseEventHandler(this.Button_MouseDown);
它进行编译,但未提出偶数

这同样适用于整个面板本身

this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Button_MouseDown);
为什么我不能在派生类中处理该事件?有什么办法使它起作用吗

这是我的InitializeComponent方法:

        private void InitializeComponent()
    {
        this.button1 = new System.Windows.Forms.Button();
        this.SuspendLayout();
        // 
        // button1
        // 
        this.button1.Location = new System.Drawing.Point(29, 140);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(72, 39);
        this.button1.TabIndex = 1;
        this.button1.Text = "button1";
        this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(button1_MouseDown);
        // 
        // MopilStatsPanel
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
        this.Controls.Add(this.button1);
        this.Name = "MopilStatsPanel";
        this.Size = new System.Drawing.Size(286, 337);
        this.ResumeLayout(false);

    }

我认为您可能需要使用MouseButtonEventHandler,而不仅仅是MouseButtonEventHandler:


向问题添加相关代码。您在哪里为事件分配处理程序?仅供参考,button1.MouseDown+=Button\u MouseDown。您是否在该按钮上有任何可能捕获事件的内容?也许是另一个面板?我无法重现你的问题。它在我的示例中起作用…不,它只是用户控件和其中的一个按钮。当我为整个控件创建事件时,它工作,除非我单击按钮。为按钮创建事件不起任何作用
this.MouseDown += new MouseButtonEventHandler(this.Button_MouseDown);