我有一个 Windows 窗体应用程序,它使用一些 Application.Idle 处理程序来更改窗体上控件的状态。
在向表单添加 ListView 后,我意识到当鼠标光标位于 ListView 上方时,Idle-Handlers 会被频繁调用。通过使用 Spy++,我看到当鼠标光标在控件上(不移动)时,控件接收到 WM_MOUSEHOVER 消息,然后触发空闲事件(在消息队列为空之后)。TreeView-Controls 也是如此。
我想知道如何禁用此行为?
从命令提示符运行此代码将显示我的意思:
using System;
using System.Windows.Forms;
public class IdleTest {
public static void Main() {
Application.Idle += delegate {
Console.WriteLine(
DateTime.Now.ToString() + " idle!" ) ;
};
Form f = new Form(){ Width=300 };
f.Controls.Add(new ListView(){ Left=0, Width=100 } );
f.Controls.Add(new TreeView(){ Left=100, Width=100 } );
f.Controls.Add(new TextBox() { Left=200, Width=100 } );
Application.Run(f) ;
}
}