如何只做一次窗?

时间:2021-10-14 06:47:47

I want to make a window topmost in a C# application. i need to make it so that while the window is loaded(the application is invoked by a third party software) it will be on top and user can browse to other windows if he needed.

我想在c#应用程序中创建一个窗口。我需要这样做,以便在加载窗口(应用程序由第三方软件调用)时,它将位于顶部,用户可以在需要时浏览到其他窗口。

I used

我使用

this.Topmost = true; 
this.TopMost=false; 

but it dont have any effect.

但是没有任何效果。

4 个解决方案

#1


1  

TopMost only applies to forms within your application. If you want to bring your form to the top of other applications running on your computer, I suggest you take a look at this question:

TopMost只适用于应用程序中的表单。如果你想把你的表格放在电脑上运行的其他应用程序的顶部,我建议你看看这个问题:

Bringing window to the front in c# using win 32 api

使用win32 api将窗口带到c#的前端

#2


0  

I can suggest you to use native API. SetWindowPos function from user32.dll

我建议您使用本机API。从user32.dll SetWindowPos函数

something like this, but it should be converted to C# code, i think it wouldn't be difficult. HWND_TOPMOST flag is just what you needed

类似这样的东西,但是它应该被转换成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  

UPDATE
READ THIS http://social.msdn.microsoft.com/forums/en-US/winforms/thread/bf3117f8-d83d-4b00-8e4f-7398b559a2dd/

更新阅读http://social.msdn.microsoft.com/forums/en - us/winforms/thread/bf3117f8 d83d - 4 - b00 - 8 e4f - 7398 b559a2dd/

If the forms are in different applications, you can get the window you want to bring to front by calling the FindWindow API, and SetForegroundWindow API to bring it to front, for more information, you can read these likes

如果表单在不同的应用程序中,您可以通过调用FindWindow API获得想要带到前台的窗口,并通过SetForegroundWindow API将其带到前台,要了解更多信息,您可以阅读这些like

FindWindow http://msdn.microsoft.com/en-us/library/ms633499(VS.85).aspx

FindWindow http://msdn.microsoft.com/en-us/library/ms633499(VS.85). aspx

SetForegroundWindow http://msdn.microsoft.com/en-us/library/ms633539(VS.85).aspx

窗体提前http://msdn.microsoft.com/en-us/library/ms633539(VS.85). aspx

#4


0  

this.Activate() 

should do the trick.

应该足够了。

#1


1  

TopMost only applies to forms within your application. If you want to bring your form to the top of other applications running on your computer, I suggest you take a look at this question:

TopMost只适用于应用程序中的表单。如果你想把你的表格放在电脑上运行的其他应用程序的顶部,我建议你看看这个问题:

Bringing window to the front in c# using win 32 api

使用win32 api将窗口带到c#的前端

#2


0  

I can suggest you to use native API. SetWindowPos function from user32.dll

我建议您使用本机API。从user32.dll SetWindowPos函数

something like this, but it should be converted to C# code, i think it wouldn't be difficult. HWND_TOPMOST flag is just what you needed

类似这样的东西,但是它应该被转换成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  

UPDATE
READ THIS http://social.msdn.microsoft.com/forums/en-US/winforms/thread/bf3117f8-d83d-4b00-8e4f-7398b559a2dd/

更新阅读http://social.msdn.microsoft.com/forums/en - us/winforms/thread/bf3117f8 d83d - 4 - b00 - 8 e4f - 7398 b559a2dd/

If the forms are in different applications, you can get the window you want to bring to front by calling the FindWindow API, and SetForegroundWindow API to bring it to front, for more information, you can read these likes

如果表单在不同的应用程序中,您可以通过调用FindWindow API获得想要带到前台的窗口,并通过SetForegroundWindow API将其带到前台,要了解更多信息,您可以阅读这些like

FindWindow http://msdn.microsoft.com/en-us/library/ms633499(VS.85).aspx

FindWindow http://msdn.microsoft.com/en-us/library/ms633499(VS.85). aspx

SetForegroundWindow http://msdn.microsoft.com/en-us/library/ms633539(VS.85).aspx

窗体提前http://msdn.microsoft.com/en-us/library/ms633539(VS.85). aspx

#4


0  

this.Activate() 

should do the trick.

应该足够了。