Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form top most?

Tags:

c#

.net

How can I display something over all other application. I want to to display something over all form of my program and all other programs open on my desktop (not mine).

*Top Most doesn't work I have tested and my browser can go OVER my application :S

Here is an image of when I use TopMost to TRUE. You can see my browser is over it...

http://www.freeimagehosting.net/uploads/5a98165605.png

like image 544
Pokus Avatar asked Nov 27 '08 18:11

Pokus


People also ask

How do you use topmost?

1. We couldn't reach the apples on the topmost branches. 2. The topmost branches were full of birds.

How to make windows form always on top?

To make the active window always on top, press Ctrl + Spacebar (or the keyboard shortcut you assigned). Press the keyboard shortcut again to disable “always on top” for the active window. For script options, right-click on the AutoHotkey icon in the system tray.

What is a top level form?

A top-level form is a window that has no parent form, or whose parent form is the desktop window. Top-level windows are typically used as the main form in an application.


1 Answers

You can use the form instance and set the property TopMost to True.


If you want to be over all Windows, there are another way with Win32 Api calls.

Here is what you could do:

In your form class add :

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);

In the form load you can add :

SetForegroundWindow(this.Handle);

This should do the trick.

Update

TopMost should do the job BUT: Top most OR/AND the Win32 Api call will only work not inside Visual Studio (well for Vista and with VS2008 I tested it... I can't tell for other). Try running the program with the .Exe from the /bin directory, it will works.

like image 146
Patrick Desjardins Avatar answered Sep 25 '22 06:09

Patrick Desjardins