代码之家  ›  专栏  ›  技术社区  ›  Samuel

有时最上面的作品

  •  2
  • Samuel  · 技术社区  · 15 年前

    似乎最顶层的属性有时会将我的应用程序置于所有其他窗口之上,但在我的测试过程中,它非常奇怪,因为有时它可以工作,而窗口仍然位于所有其他(外部应用程序)窗口之上,但有时它什么也不做。我甚至尝试过使用WS_EX_TOPMOST标志,方法是使用对setWindowLong()的Win32 API调用设置它。他们谁也没有把窗户放在上面。除了用最上面的方法外,还有没有其他方法可以在每个打开的窗口的顶部保持一个窗口?或者我还应该知道一些最上面的事情吗?

    4 回复  |  直到 15 年前
        1
  •  5
  •   Pierre Arnaud    15 年前

    我只是用这个:

    form.TopLevel = true;
    form.TopMost  = true;
    

    这使得窗口处于顶层(即它没有父窗口,并且作为应用程序的主要形式),然后确保它是最顶层(即显示在所有其他非最顶层窗口之上)。它总是很有魅力。

    请注意,我在展示橱窗前会这样做。

        2
  •  2
  •   Ken    15 年前

    我在以下win32 api调用中遇到了运气:

    const int SW_SHOW = 5;
    BringWindowToTop(form.Handle);
    ShowWindow(form.Handle, SW_SHOW);
    
        3
  •  1
  •   Brian R. Bondy    15 年前

    除了 Form.TopMost SetForegroundWindow .

    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("user32", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
    public static extern bool SetForegroundWindow(IntPtr hwnd);
    

    然后打电话 SetForegroundWindow(this.Handle) .

        4
  •  0
  •   Martin.Martinsson    8 年前

    User32.AllowSetForegroundWindow((uint)Process.GetCurrentProcess().Id);
    User32.SetForegroundWindow(Handle);
    User32.ShowWindow(Handle, User32.SW_SHOWNORMAL);