Search code examples
c#.netwinformsmodal-dialogfullscreen

Hidden WinForms modal dialogs


I have a WinForms app (.NET 4) that has a main form and two modal dialogs as follows:

  • FormMain: Run via Application.Run(new FormMain()).
  • FormSettings: Launched from FormMain: new FormSettings().ShowDialog(this).
  • FormCredentials: Launched from FormSettings: new FormCredentials().ShowDialog(this).

When all three forms have normal borders and sizing, everything works fine. However, this app is supposed to appear in full screen and I use the following code only on FormMain to achieve that:

        FormMain.FormBorderStyle = FormBorderStyle.FixedSingle;
        FormMain.MinimizeBox = false;
        FormMain.MaximizeBox = false;

        FormMain.Text = "";
        FormMain.ControlBox = false;
        FormMain.ShowInTaskbar = false;
        FormMain.TopMost = !Configuration.Debug;
        FormMain.TopLevel = true;

The other two dialogs have their FormBorderStyle = FormBorderStyle.FixedSingle.

So FormMain launches FormSettings as a modal dialog and FormSettings launches FormCredentials as a modal dialog. FormCredentials ALWAYS disappears behind FormMain. In fact any third-level form disappears behind FormMain.

Searching for this behaviour brought up suggestions for specifying the form owner which I'm already doing in the call to ShowDialog(this).

Any other reasons for it to behave this way?

EDIT: This only happens in release mode so the the line FormMain.TopMost = !Configuration.Debug may have something to do with it. That line ensures the end-user cannot get out of the app when it is running as a kiosk.


Solution

  • Please check this url for TopMost property - you dont need to set anything, comment out this line which does set topmost property, and check, Normally it should work fine.

    https://msdn.microsoft.com/en-us/library/system.windows.forms.form.topmost(v=vs.110).aspx

    Edit : description about TopMost form :

    A topmost form is a form that overlaps all the other (non-topmost) forms even if it is not the active or foreground form. Topmost forms are always displayed at the highest point in the z-order of the windows on the desktop. You can use this property to create a form that is always displayed in your application, such as a Find and Replace tool window.