我想在C#应用程序中创建一个窗口。我需要这样做,以便在加载窗口时(应用程序由第三方软件调用)它将位于顶部,用户可以根据需要浏览其他窗口。
我用过
this.Topmost = true;
this.TopMost=false;
但它没有任何效果。
答案 0 :(得分:1)
TopMost
仅适用于您的应用程序中的表单。如果您想将表单放在计算机上运行的其他应用程序的顶部,我建议您看一下这个问题:
答案 1 :(得分:0)
更新
请阅读http://social.msdn.microsoft.com/forums/en-US/winforms/thread/bf3117f8-d83d-4b00-8e4f-7398b559a2dd/
如果表单在不同的应用程序中,您可以通过调用FindWindow API和SetForegroundWindow API将它带到前面的窗口将其带到前面,有关详细信息,您可以阅读这些内容。
FindWindow函数
http://msdn.microsoft.com/en-us/library/ms633499(VS.85).aspx
SetForegroundWindow http://msdn.microsoft.com/en-us/library/ms633539(VS.85).aspx
答案 2 :(得分:0)
我建议你使用原生API。来自user32.dll的SetWindowPos函数
这样的东西,但它应该转换为C#代码,我认为这并不困难。 HWND_TOPMOST标志正是您所需要的
RECT rect;
// get the current window size and position
GetWindowRect(hWnd, &rect );
// now change the size, position, and Z order
// of the window.
SetWindowPos(hWnd , // handle to window
HWND_TOPMOST, // placement-order handle
rect.left, // horizontal position
rect.top, // vertical position
rect.right, // width
rect.bottom, // height
SWP_SHOWWINDOW );// window-positioning options
答案 3 :(得分:0)
this.Activate()
应该这样做。