在Visual Studio 2008 C#应用程序中,我使用按钮控制。我尝试获取MouseDown事件的按钮(该事件在Button继承自的Control类中定义) 如果我写这个:
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);
}
答案 0 :(得分:0)
我认为你可能需要使用 MouseButtonEventHandler 而不只是 MouseEventHandler :
this.MouseDown += new MouseButtonEventHandler(this.Button_MouseDown);