问题描述
|
我想取消鼠标单击,鼠标上移或鼠标下移,即使发生在我的.NET控件上也是如此。
我希望在
EventArgs
中有一个Cancel参数,但是我没有在ѭ1see中看到类似的参数。
有其他方法可以执行此操作,还是应该听其他事件?
解决方法
只是重写处理程序,不要调用基类函数。
, 一个简单的解决方案就是杀死焦点,创建自己的类:
public class ViewOnlyTextBox : System.Windows.Forms.TextBox {
// constants for the message sending
const int WM_SETFOCUS = 0x0007;
const int WM_KILLFOCUS = 0x0008;
protected override void WndProc(ref Message m) {
if(m.Msg == WM_SETFOCUS) m.Msg = WM_KILLFOCUS;
base.WndProc (ref m);
}
}