HelloWorld
HelloWorld

Reputation: 1091

How to keep window always on top

How I can keep my window staying always on top even if there is a window of another application with Topmost = true option activated and trying to stay in front of my window?

Upvotes: 1

Views: 4429

Answers (3)

ETFovac
ETFovac

Reputation: 111

Easiest way(assuming you allready have topmost promery set) would be calling

myform.BringToFront();

on FIXED but relativly small time intervals(see Timer class), through all the time form must stay on top.

If calling this was conected to event that inform you of losing privileg of beeing on top, that could possibly cause resource-fihgts between multiple applications. Price of beeing safe is that some other program might be cheating by lisstening to informations when he is overthroned by your program, but the only solution for you wolud than be to kill that other program if you want to stay on top all the time :D

Upvotes: 1

aevitas
aevitas

Reputation: 3833

You can do a platform invoke on BringWindowToTop to achieve this:

[DllImport("user32.dll", SetLastError=true)]
static extern bool BringWindowToTop(IntPtr hWnd);

[DllImport("user32.dll", SetLastError=true)]
static extern bool BringWindowToTop(HandleRef hWnd);

And call to it when the FocusLost event fires.

Upvotes: 2

Manish Basantani
Manish Basantani

Reputation: 17499

It should be possible by setting the Focus on window, from OnFocusLost event handler.

Upvotes: 1

Related Questions