如何防止改变Z序控制? [英] How to prevent a control from changing Z order?

查看:131
本文介绍了如何防止改变Z序控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那里的.Net我使用的WndProc命中测试,以便用鼠标运行时调整其大小的用户控制。



的问题是,命中后测试succedes(按下鼠标,拖动来调整大小,鼠标释放)控制向上跳跃在Z顺序和废墟它的形式位置。



我需要因为点击测试这是一个非常定制的控制。



有没有WndProc的办法从改变其Z序?



停止控制< 。p>感谢



点击测试代码:

 保护覆盖无效的WndProc(参考消息M){
如果(的designMode&安培;!&安培;可调整大小和放大器;及(m.Msg == Win32Wrapper.WM_NCHITTEST)){
点命中=新的点((INT) m.LParam&安培; 0xFFFF的,(INT)m.LParam>> 16);
命中= this.PointToClient(打);
INT DistToBorder = 5;
如果(Hit.X< DistToBorder){
如果(Hit.Y< DistToBorder){
m.Result =(IntPtr的)Win32Wrapper.HTTOPLEFT;
的回报;
}
如果(Hit.Y> this.ClientRectangle.Bottom - DistToBorder){
m.Result =(IntPtr的)Win32Wrapper.HTBOTTOMLEFT;
的回报;
}
m.Result =(IntPtr的)Win32Wrapper.HTLEFT;
的回报;
}
,否则如果(Hit.X> ClientRectangle.Right - DistToBorder){
如果(Hit.Y< DistToBorder){
m.Result =(IntPtr的)Win32Wrapper .HTTOPRIGHT;
的回报;
}
,否则如果(Hit.Y> this.ClientRectangle.Bottom - DistToBorder){
m.Result =(IntPtr的)Win32Wrapper.HTBOTTOMRIGHT;
的回报;
}
m.Result =(IntPtr的)Win32Wrapper.HTRIGHT;
的回报;
}
,否则如果(Hit.Y< DistToBorder){
m.Result =(IntPtr的)Win32Wrapper.HTTOP;
的回报;
}
,否则如果(Hit.Y> this.ClientRectangle.Bottom - DistToBorder){
m.Result =(IntPtr的)Win32Wrapper.HTBOTTOM;
的回报;
}
}


解决方案

是你确定它是造成问题的命中测试?你是如何调整的控制?一种选择是使用P-调用传递给它SWP_NOZORDER标志调用SetWindowPos。


I have user control in .Net where I use a hit test in WndProc to allow resizing it in runtime with the mouse.

The problem is that after the hit test succedes (mouse press, drag to resize, mouse release) the control jumps upwards in the Z order and ruins it position in the form.

I need the hit test since it's a very customized control.

Is there a way in WndProc to stop the control from changing it's Z order ?

Thanks.

The hit test code:

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;
    }
  }

解决方案

Are you sure it's the hit test that's causing the problem? How are you resizing the control? One option is to call SetWindowPos using p-invoke passing it SWP_NOZORDER flag.

这篇关于如何防止改变Z序控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆