Keep my application on top

  • Thread starter Thread starter Mario Reiley
  • Start date Start date
M

Mario Reiley

Hi, Group

I am C# and VB.6 programmer but in this moments I have the followin
question:

How Can I keep my application on the top of all applications on my Windows
desktop.

Please let me know

Best regard
MArio
 
I am C# and VB.6 programmer but in this moments I have the followin
question:

How Can I keep my application on the top of all applications on my Windows
desktop.

I don't believe you can without reverting to Win32 API funtions. I simply
needed a BringToFront for the main application window and couldn't find it,
Win32's SetForeGroundWindow seemed the only way.

Martin.
 
Mario,

You can get top most behavior by setting the form property TopMost to
boolean true; Something like this:

/* ************************************** */
private void Form1_Load(object sender, System.EventArgs e) {
this.TopMost = true;
}


This will keep your for above all other windows, until another application
sets a window to TopMost -- then all TopMost windows compete for top most
based on foreground/active states...

One side note - debugging an app with a TopMost window is a bit of a pain -
the Debugger/IDE is ends up behind the app form...

I hope this helps a bit....

regards
roy fine
 
You can get top most behavior by setting the form property
TopMost to boolean true;

I don't know what I did wrong before but this just works now. I had been
messing with it and found it didn't work for forms, I must have been
screwing something up. I ended up doing

// couldn't find a .NET-way to bring the window
// to top, reverting to old Win32 functions...
[DllImport("User32.dll")]
public static extern Int32 FindWindow(String lpClassName,String
lpWindowName);
[DllImport("User32.dll")]
public static extern Int32 SetForegroundWindow(int hWnd);

private void triMain_Click(object sender, System.EventArgs e)
{
Show();
int hWnd = FindWindow(null, "Pacemaker"); // Win32 API, don't want
to use this
SetForegroundWindow(hWnd); // Wim32 API, don't want to use this
}

Now it is clean:

Show();
TopMost = true;
TopMost = false;

I am resetting TopMost to false because I just want it to bring the form to
top when the tray icon is clicked and not stay on top persistently.

Thank you!

Martin.
 
Back
Top