Maximized form is visible on the screen before call to OnShow()

Steps to reproduce:
  1. Create new Windows Application project
  2. Add control to the main form (e.g. ListView)
  3. Set form's WindowState to Maximized
  4. Override OnLoad() and OnShow() methods
  5. Set breakpoints on the calls to the base and run under debugger
  6. Note that the form is present on the screen when OnLoad() is hit (before call to OnShow())
  7. Note that form's content (the ListView) isn't visible yet
  8. Repeat same steps for WindowState set to Normal and compare


Answer this question

Maximized form is visible on the screen before call to OnShow()

  • Shaf2k

    You're not seeing your form, you are seeing the "ghost" that Windows XP creates for unresponsive windows. Note the class name of the window when you look at it with Spy++, the generic icon and the "Ending program" dialog you'll immediately get when you click the close button. It is a bit odd that it shows up so quickly but that would be an XP issue, not a Windows Forms problem.

    Is this really a problem


  • S10n

    using any visual designer is not proper to learn something in depth. The following few lines of code will do it quite painlessly, and everything will be in front of ur eyes--

    using System.Drawing;
    using System.Windows.Forms;

    class Form1 : Form {

    private ListView ListView1;

    public Form1() {
    ListView1 = new ListView();
    ListView1.Location = new Point(22,21);
    ListView1.Size = new Size(569,356);

    this.Text = "Form1";
    this.Size = new Size(618,422);
    this.WindowState=FormWindowState.Maximized;
    this.Controls.Add(ListView1);
    }
    static void Main() {
    Application.Run(new Form1());
    }
    }
    To compile it use:-
    csc /t:winexe filename.cs

  • Rick_Parker

    Yes, you are right. But isn't it a bit odd that ghost window appears only when WindowState set to Maximized
    It is not a problem but an annoyance from user's perspecitve when an empty form flashes for an isntant.

  • dylanh

    Proper way to answer a question in depth should start with understanding it first. Quite painless appearance of the list view wasn't my primary concern. Its absense is an unfortunate side-effect of using visual designer. Not as "improper way to learn something in depth", mind you. May I suggest overriding OnShown() and OnLoad() methods in your example Then everything will be in front of you eyes. Specifically, the form will be visible on the screen at the OnLoad() and before the OnShown().
  • Maximized form is visible on the screen before call to OnShow()