窗体代码中的那个鼠标事件是我抄书上的代码,但为什么鼠标事件不起作用呢?难道是电子工业出版社的书有错吗?请指教。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 鼠标事件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_MouseHover(object sender, EventArgs e)
{
MessageBox.Show("鼠标过来了!");
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 鼠标事件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_MouseHover(object sender, EventArgs e)
{
MessageBox.Show("鼠标过来了!");
}
}
}
代码是这样的
在form1下的Form1.Designer.cs中
this.button1.Location = new System.Drawing.Point(12, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "前一个";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
这是窗体生成器生成的代码,而我们要在后面加一句
this.button1.MouseHover+=new System.EventHandler(button1_MouseHover);
这样你的事件就可以触发了
希望对你有帮助
这句有没有,需要定义这个事件先!