InputMan中日期控件GcDateTime
如何禁掉鼠标滚轴在日期控件中的上下移动日期的行为呢? 分两种情况处理:1. 如果连键盘滚动,侧边按钮(Spin按钮)也一并禁用,直接将Spin.AllowSpin = false即可。
2. 如果仅仅用鼠标滚轮,可以考虑使用MessageFilter之类的技术,例如:
public partial class Form1 : Form
{
private DisableMouseWheelMessageFilter _filter = new DisableMouseWheelMessageFilter();
public Form1()
{
InitializeComponent();
_filter.RegistForbiddenMouseWheel(this.gcDateTime1);
Application.AddMessageFilter(_filter);
}
}
internal class DisableMouseWheelMessageFilter : IMessageFilter
{
private List<Control> _disableMouseWheelControlList = new List<Control>();
public void RegistForbiddenMouseWheel(Control control)
{
_disableMouseWheelControlList.Add(control);
}
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == 0x20A) // WM_MOUSEWHEEL
{
foreach (var control in _disableMouseWheelControlList)
{
if (control.ContainsFocus || control.Focused)
{
return true;
}
}
}
return false;
}
}
嗯,解决了。谢谢
页:
[1]