我的表单上有一个取消按钮。我想在 WndProc
方法中确定单击了这个 Cancel
按钮并为其编写一些代码。这是绝对必要的,因为否则我无法取消所有其他尚未执行的控件验证事件。
请帮忙。
.NET - 2.0,WinForms
最佳答案
这是您如何解析 WndProc 消息以在子控件上单击鼠标左键:
protected override void WndProc(ref Message m)
{
// http://msdn.microsoft.com/en-us/library/windows/desktop/hh454920(v=vs.85).aspx
// 0x210 is WM_PARENTNOTIFY
// 513 is WM_LBUTTONCLICK
if (m.Msg == 0x210 && m.WParam.ToInt32() == 513)
{
var x = (int)(m.LParam.ToInt32() & 0xFFFF);
var y = (int)(m.LParam.ToInt32() >> 16);
var childControl = this.GetChildAtPoint(new Point(x, y));
if (childControl == cancelButton)
{
// ...
}
}
base.WndProc(ref m);
}
顺便说一句:这是 32 位代码。
关于winforms - 捕获某个按钮点击的WndProc消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10635518/