C# 如何防止控件更改Z顺序?

C# 如何防止控件更改Z顺序?,c#,windows,winapi,messaging,C#,Windows,Winapi,Messaging,我在.Net中有一个用户控件,我在WndProc中使用一个命中测试,允许在运行时用鼠标调整它的大小 问题是,在命中测试成功后(鼠标按下、拖动以调整大小、鼠标释放),控件按Z顺序向上跳跃,并破坏其在窗体中的位置 我需要点击测试,因为它是一个非常定制的控件 WndProc中是否有方法阻止控件更改其Z顺序 谢谢 命中测试代码: protected override void WndProc(ref Message m) { if (!DesignMode && Sizeable &

我在.Net中有一个用户控件,我在WndProc中使用一个命中测试,允许在运行时用鼠标调整它的大小

问题是,在命中测试成功后(鼠标按下、拖动以调整大小、鼠标释放),控件按Z顺序向上跳跃,并破坏其在窗体中的位置

我需要点击测试,因为它是一个非常定制的控件

WndProc中是否有方法阻止控件更改其Z顺序

谢谢

命中测试代码:

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;
    }
  }
受保护的覆盖无效WndProc(参考消息m){
如果(!DesignMode&&Sizeable&&(m.Msg==Win32Wrapper.WM\u nchitest)){
点命中=新点((int)m.LParam&0xFFFF,(int)m.LParam>>16);
Hit=此。指向客户端(Hit);
int-DistToBorder=5;
if(Hit.Xthis.ClientRectangle.Bottom-distToOrder){
m、 结果=(IntPtr)Win32Wrapper.HTBOTTOMLEFT;
返回;
}
m、 结果=(IntPtr)Win32Wrapper.HTLEFT;
返回;
}
else if(Hit.X>ClientRectangle.Right-distToOrder){
如果(命中Ythis.ClientRectangle.Bottom-distToOrder){
m、 结果=(IntPtr)Win32Wrapper.HTBOTTOMRIGHT;
返回;
}
m、 结果=(IntPtr)Win32Wrapper.HTRIGHT;
返回;
}
else if(Hit.Ythis.ClientRectangle.Bottom-distToOrder){
m、 结果=(IntPtr)Win32Wrapper.HTBOTTOM;
返回;
}
}

没有回答,但您是否尝试过跟随他而不是滚动您自己的deigner模式交互?

窗口对话框通过控件窗口的z顺序管理选项卡顺序和焦点,给予焦点的控件被提升到顶部

如果希望自定义控件保留其相对z定位,请确保其属性不指示其为TABSTOP或以其他方式能够接收焦点。即,如果禁用,它是否工作


另一方面,即使您成功阻止控件的z顺序更改,它也会在用户与其他控件交互时被隐式重新定位。

要防止z顺序更改,您应该捕获
WM_WINDOWPOSCHANGING
消息并设置
SWP_NOZORDER
标志。

您确定这是成功的吗这是导致问题的原因吗?您如何调整控件的大小?一个选项是使用p-invoke调用SetWindowPos,并将其传递给SWP_NOZORDER标志。

关于如何在NodeJS/node ffi/Electron中执行此操作:我认为这正是我多年来一直试图找到的,我将看看是否能让它为我工作。。。