none
Frustrating Form "topmost" problem RRS feed

  • Question

  • I've developed a Forms app that show two windows.

    One is a dialog box that allows various actions to be performed, the other is a modeless window that shows a simply activity log as the app runs. As the user clicks things on the main dialog various state messages get written to the log window. The log window is display only, no inputs. It can be min/max/resized and moved and scrolled but that's all.

    To get this work I had to run the log window in a dedicated thread 

                logThread = new Thread((a) => { Application.Run((Form)a); });
                logThread.Start(log);

    This works fine I can move and scroll the log window fine and move to the dialog and all is fine.

    My only pain is that when I start the app the log window always ends up on top of the dialog and a user has to click the dialog go give it focus.

    I've tried a ton of things, setting TopMost, TopLevel, using an AutoResetEvent so that I don't attempt the ShowDialog until the log form has been shown, even putting a sleep in the app before I do a ShowDialog. Even with a Sleep of 1 second the dialog always gets shown behind the log window!

    I even tried changing the above code to be:

                logThread = new Thread((a) => { ((Form)a).ShowDialog(); });
                logThread.Start(log);
    


    Saw no ill effects when I run it but the dialog again is always at the back when the app starts!

    Any ideas?

    Thx


    • Edited by Captain Kernel Saturday, September 16, 2017 9:38 PM
    • Moved by CoolDadTx Sunday, September 17, 2017 5:21 AM Winforms related
    Saturday, September 16, 2017 9:28 PM

All replies

  • The topmost game is a terrible game, and usually everyone looses. The only way to win is not to play it at all:
    https://blogs.msdn.microsoft.com/oldnewthing/20110310-00/?p=11253

    The behavior you describe might be better solved with something like a Docking control (not to be mistaken with the Dock Control), where the logwindow is permanently/usually "undocked". You can see a proper docking control (container) in action in Visual Studio actually. If there is a easy docking control container avalible depends on the Display technolgy you are using. You really should specify that, so we can properly help you:
    Frameworks, Programming for .NET, Display technologies and the like


    Remember to mark helpfull answers as helpfull and close threads by marking answers.



    Sunday, September 17, 2017 12:26 AM
  • The topmost game is a terrible game, and usually everyone looses. The only way to win is not to play it at all:
    https://blogs.msdn.microsoft.com/oldnewthing/20110310-00/?p=11253

    The behavior you describe might be better solved with something like a Docking control (not to be mistaken with the Dock Control), where the logwindow is permanently/usually "undocked". You can see a proper docking control (container) in action in Visual Studio actually. If there is a easy docking control container avalible depends on the Display technolgy you are using. You really should specify that, so we can properly help you:
    Frameworks, Programming for .NET, Display technologies and the like


    Remember to mark helpfull answers as helpfull and close threads by marking answers.



    Thanks, the display technology is fully docked RichTextBox control. It displays only text, uses text color here and there. There are no user inputs other than: min, max, resize and move (the window cannot be closed except by closing the main dialog).

    I kind of like your docking idea because I may have a need to support multiple logs, potentially.

    Sunday, September 17, 2017 2:53 PM
  • Thanks, the display technology is fully docked RichTextBox control. It displays only text, uses text color here and there. There are no user inputs other than: min, max, resize and move (the window cannot be closed except by closing the main dialog).

    I kind of like your docking idea because I may have a need to support multiple logs, potentially.

    Hi Korporal,

    So have you solved this problem now?

    If so, hope you can close this thread by marking the helpful reply as answer as this will help others looking for the same or similar issues down the road.

    Or please provide more details if not.

    Best Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 19, 2017 9:23 AM
    Moderator