0

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.

I used

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

but it dont have any effect.

Yuriy Faktorovich
  • 67,283
  • 14
  • 105
  • 142

4 Answers4

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:

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

Community
  • 1
  • 1
Ocelot20
  • 10,510
  • 11
  • 55
  • 96
0

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

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 http://msdn.microsoft.com/en-us/library/ms633499(VS.85).aspx

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

Student
  • 3,469
  • 7
  • 35
  • 42
0

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

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

 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
Disposer
  • 667
  • 1
  • 7
  • 23
0
this.Activate() 

should do the trick.

ilias
  • 2,620
  • 2
  • 27
  • 37