1

I have a WinForms application with 2 Forms. Both are TopMost, but I would want to have one of them to always be on top of the second one.

It's something like "even more TopMost.

Is this possible?

Calling BringToFront() in a timer causes the form to flicker.

bytecode77
  • 14,163
  • 30
  • 110
  • 141
  • 5
    Raymond Chen's response is here: http://blogs.msdn.com/b/oldnewthing/archive/2005/06/07/426294.aspx – adv12 May 28 '15 at 13:36
  • @GrantWinney: I'm going to guess they want it to *stay* topmost. Calling `BringToFront` will only keep it topmost until the other form gets clicked and pulled to the front. Not to say it's still not a horrible way to solve the problem. – Matt Burland May 28 '15 at 13:41
  • @GrantWinney Both windows are TopMost, but one needs to be even more, like described. I have to call `BringToFront()` for the lower topmost window in a timer, too. This is in order to avoid other windows popping in front of it. – bytecode77 May 28 '15 at 13:41
  • You should be able to fire a method (like `BringToFront`) when the second form is clicked to focus the first form again. – Der Kommissar May 28 '15 at 13:43
  • @adv12 Its not that he wants both to be the top most, he wants one to be top most and the other to be 2nd from top most. But there is no `SecondFromTopMost = true` in winforms. – Scott Chamberlain May 28 '15 at 13:44
  • @EBrown This would work in a casual situation, but the form in the background acts as a screen overlay which lets the user "click-through", if you know what I mean. – bytecode77 May 28 '15 at 13:44
  • 2
    You may have to rethink your design because I don't think this is possible for reason alluded to in the link @adv12 posted. Even adding more levels of *topmostness* just shifts the problem around. How many levels are enough? If the background form is a screen overlay, as you say, is it fullscreen? Could you make the *topmostest* form just be a child of that form so it'll always be above it? – Matt Burland May 28 '15 at 13:47
  • Set Topmost property of one form to false. It will always be behind the one which has TopMost set to true. – Sriram Sakthivel May 28 '15 at 13:47
  • 1
    @SriramSakthivel: I think the OP wants the non-topmost form to still be topmost to *everything else*, however. – Matt Burland May 28 '15 at 13:49
  • 2
    The problem with `TopMost` is how does Windows decide what is *ultimately* `TopMost`? Does your application take precedence because the name starts with an `A` instead of a `D`, or does the other application take precedence because it has a lower `GUID` in the identifier, or a shorter filename? Additionally, if Windows *could* decide who gets to be `TopMost` ultimately, what happens when application `A` uses some hack to make Windows make it the `TopMostest`, and application `B` uses the same hack? If your design requires `TopMost` functionality, I recommend you reevaluate it. – Der Kommissar May 28 '15 at 14:50

1 Answers1

1

Check the SetWindowPos function.

It might be helpful.


EDIT:

After reviewing these answers (1, 2, 3), it's not possible to do such thing.

Community
  • 1
  • 1
Aly Elhaddad
  • 1,913
  • 1
  • 15
  • 31