窗体代码中的那个鼠标事件是我抄书上的代码,但为什么鼠标事件不起作用呢?难道是电子工业出版社的书有错吗?请指教。
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("鼠标过来了!");
        }       
    }
}

解决方案 »

  1.   

    MouseHover事件要求鼠标停在button1上面一段时间,你要马上发生这个事件的话,用mouseEnter事件,这是鼠标刚进入button就能发生的.
      

  2.   

    控件默认生成的事件不是button1_MouseHover,而是button1_Click  如果不去手动编辑的话,这个事件是不存在的,
    代码是这样的
    在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);
    这样你的事件就可以触发了
    希望对你有帮助
      

  3.   

    this.button1.MouseHover+=new System.EventHandler(button1_MouseHover); 
    这句有没有,需要定义这个事件先!