none
Showing form for the first time RRS feed

  • Question

  • Hi,

    I recently posted this question and my post got deleted for no apparent reason so I'll try again. When a form first shows, I get an outline rectangle expanding before the form appears. I have an application with lots of forms in that I load at the start and iterate through (calling form.Show()) to "preload" them. This makes loads of outline rectangles appear and it looks a mess. Is there anyway to prevent this?

    Cheers,

    Neil.
    Monday, March 2, 2009 9:11 AM

Answers

  • ScottyDoesKnow said:

    Mr B, what John is saying is that you don't need to call form.Show() on any of the forms until you want to show them. When you create the form object, everything in the constructor runs. So if you have your loading code in the constructor, you don't need to call Show(). If you have code in the Shown event of the form, try moving it to the constructor.



    Yeh, pretty much.  I was thinking of code in the load event, but anywhere after the constructor.  And the constructor for the individual forms, not the constructor of the main form.  There is just no reason that I can think of, if all the form loading code is in the constructor,  that one showing should be different from any other.
    Monday, March 2, 2009 3:29 PM

All replies

  •  Put the code to load whatever you need to load in the constructor after InitializeComponent().  The code will run when the form is instantiated, but before it is loaded and shown.
    Monday, March 2, 2009 9:28 AM
  • I'm not sure you understand my problem. My application is basically a dialogue based app and has about ten different forms which I keep open all the time. Whenever I show a form for the first time it "builds" that form and has the effect of showing an outline rectangle growing from the taskbar to fill the screen before showing the form. Putting the form.Show()'s of the individual forms in the constructor of my main form has no effect.

    Neil.
    Monday, March 2, 2009 9:35 AM
  • You don't understand my answer.  Build the form before you show it for the first time.  What is the purpose of Showing  the individual forms before the main form is constructed?
    Monday, March 2, 2009 9:39 AM
  • I think we are both misunderstanding each other here. My point is this, whenever a form is shown for the first time by calling form.Show(), it shows the outline of the form first and expands that before showing the form.
    Monday, March 2, 2009 11:54 AM
  • There should be no difference whether the form is shown for the first time or the 100th time following my insructions. 
    Monday, March 2, 2009 12:02 PM
  • What does the Load event handler of those forms do?  This Q&A could take a while.  Best thing to do is to put a sample project that has this behavior on a file sharing service, like skydrive.live.com


    Hans Passant.
    Monday, March 2, 2009 1:42 PM
    Moderator
  • Mr B, what John is saying is that you don't need to call form.Show() on any of the forms until you want to show them. When you create the form object, everything in the constructor runs. So if you have your loading code in the constructor, you don't need to call Show(). If you have code in the Shown event of the form, try moving it to the constructor.
    Monday, March 2, 2009 3:15 PM
  • ScottyDoesKnow said:

    Mr B, what John is saying is that you don't need to call form.Show() on any of the forms until you want to show them. When you create the form object, everything in the constructor runs. So if you have your loading code in the constructor, you don't need to call Show(). If you have code in the Shown event of the form, try moving it to the constructor.



    Yeh, pretty much.  I was thinking of code in the load event, but anywhere after the constructor.  And the constructor for the individual forms, not the constructor of the main form.  There is just no reason that I can think of, if all the form loading code is in the constructor,  that one showing should be different from any other.
    Monday, March 2, 2009 3:29 PM
  • Thanks for all your help on this guys. I found out where my original post had gone, it had been moved to the smart device forum as something I forgot to mention is that this is running on WinCE. Also, my forms are all inherited forms and there's a lot of code in the parent form that I had forgotten about. Looks like I need a bit of a re-design.

    Thanks again,

    Neil.
    Tuesday, March 3, 2009 8:38 AM