using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
bool flag = false;
public Form1()
{
InitializeComponent();
}
private bool MyTrackMouseEvent(IntPtr handle)
{
TRACKMOUSEEVENT tme = new TRACKMOUSEEVENT();
tme.dwFlags = 1; //注意这里,这里只重置了TME_HOVER
tme.hwndTrack = handle;
return _TrackMouseEvent(tme);
}
[DllImport("comctl32.dll", ExactSpelling = true)]
private static extern bool _TrackMouseEvent(TRACKMOUSEEVENT tme);
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if (flag)
{
MyTrackMouseEvent((sender as Control).Handle);
flag = !flag;
}
}
private void button1_MouseHover(object sender, EventArgs e)
{
textBox1.AppendText(DateTime.Now.ToString()+"/n");
flag = true;
}
}
[StructLayout(LayoutKind.Sequential)]
public class TRACKMOUSEEVENT
{
public int cbSize;
public int dwFlags;
public IntPtr hwndTrack;
public int dwHoverTime;
public TRACKMOUSEEVENT() {
this.cbSize = Marshal.SizeOf(typeof(TRACKMOUSEEVENT));
this.dwHoverTime = 400;
}
}
}