我在 .Net 中有用户控件,我在 WndProc 中使用命中测试,以允许在运行时使用鼠标调整其大小。
问题是,命中测试成功后(按下鼠标、拖动以调整大小、释放鼠标),控件会按 Z 顺序向上跳跃并破坏其在窗体中的位置。
我需要命中测试,因为它是一个非常定制的控件。
WndProc 中有没有办法阻止控件更改其 Z 顺序?
Thanks.
命中测试代码:
protected override void WndProc(ref Message m) {
if (!DesignMode && Sizeable && (m.Msg == Win32Wrapper.WM_NCHITTEST)) {
Point Hit = new Point((int)m.LParam & 0xFFFF, (int)m.LParam >> 16);
Hit = this.PointToClient(Hit);
int DistToBorder = 5;
if (Hit.X < DistToBorder) {
if (Hit.Y < DistToBorder) {
m.Result = (IntPtr)Win32Wrapper.HTTOPLEFT;
return;
}
if (Hit.Y > this.ClientRectangle.Bottom - DistToBorder) {
m.Result = (IntPtr)Win32Wrapper.HTBOTTOMLEFT;
return;
}
m.Result = (IntPtr)Win32Wrapper.HTLEFT;
return;
}
else if (Hit.X > ClientRectangle.Right - DistToBorder) {
if (Hit.Y < DistToBorder) {
m.Result = (IntPtr)Win32Wrapper.HTTOPRIGHT;
return;
}
else if (Hit.Y > this.ClientRectangle.Bottom - DistToBorder) {
m.Result = (IntPtr)Win32Wrapper.HTBOTTOMRIGHT;
return;
}
m.Result = (IntPtr)Win32Wrapper.HTRIGHT;
return;
}
else if (Hit.Y < DistToBorder) {
m.Result = (IntPtr)Win32Wrapper.HTTOP;
return;
}
else if (Hit.Y > this.ClientRectangle.Bottom - DistToBorder) {
m.Result = (IntPtr)Win32Wrapper.HTBOTTOM;
return;
}
}
为了防止 Z 顺序改变你应该抓住WM_WINDOWPOSCHANGING
消息并设置SWP_NOZORDER
flag.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)