Link to home
Start Free TrialLog in
Avatar of WyleOP
WyleOPFlag for United States of America

asked on

VB.NET Show form after controls are rendered

I have a VB.NET form with a large number of controls within a tablelayoutpanel.  When I show the form, it takes quite a while to load and causes a great deal of flicker.  Is there a way I can create the form, but not show it until all the controls are rendered?  Right now I'm doing a simple:

Dim frm as myForm()
farm.show()
Avatar of Aanvik
Aanvik

you can Load your form first before showing it.
Avatar of WyleOP

ASKER

For example?
For 50p? That must be real easy! Use:

Me.SuspendLayout()

' do your thing of adding controls

Me.ResumeLayout()
Avatar of WyleOP

ASKER

I'm not dynamically adding controls.  They are added via the designer.  
Then set them all to invisible. Use the above code and make the visible. Then call ResumeLayout.
If you'd like a super-easy solution, do this:
1) Add a Timer to your form
2) Call the timer, "FormLoadTimer" and set the Interval to 100
3) Remove ALL code from your FormLoad event - move all the code into a new method called, "FormInitialize"
4) In the (now empty) FormLoad - turn on your timer, "FormLoadTimer.Enabled = True"
5) In the FormLoadTimer_Tick event, put the following code:
Sub FormLoadTimer_Tick(blah blah) Handles me.FormLoadTimer.Tick
      FormLoadTimer.Enabled = False
      FormInitialize()
End Sub

The form will load, setup all controls - resize the HORRIBLY SLOW TableLayoutPanel, get all of your painting done... Then it'll display the whole thing all at once, nice and clean when the Timer ticks...

Hope this helps.
-LK
Avatar of WyleOP

ASKER

I'll give that a try, but becasue of the HORRIBLY SLOW TableLayoutPanel, any moving or resizing of the form causes the same issue.  I may need to look for an alternative to the TableLayoutPanel.  Arranging the controls individually is jut not working.  
I don't really understand why you haven't given the SuspendLayout a try. there are many ways of doing so, but the main thing is, whenever you change something, resize something or add something, use SuspendLayout. Here's a post that reports going from 20 seconds rendering to 2-3 seconds http://www.tek-tips.com/viewthread.cfm?qid=1437231&page=4. It shouldn't be too hard to change your design slightly to use this technique.
Avatar of WyleOP

ASKER

Since I'm not dynamically adding controls, where do you suggest I put the SuspendLayout code?
Hold on, I'll give you an example.
ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Abel's right ya know... his solution will definately make the 'load' go a ton faster but as for resizing your form with that TableLayoutPanel docked for resizing... you'll have to trap the form's resize to prevent the repeated refreshing of the TableLayoutPanel.

In that case, you might try suspending the layout while your form is resizing (Form.ResizeBegin) and then resume your layout when the resize is complete (Form.ResizeComplete)

Unfortunately this will result in a 'ghosting' look that is very unattractive as well.  In my case(s) I just turn the TableLayoutPanel.Visible = False when the resize begins and back to True when the resize is complete.
thanks, lkalvin. Funny, I forgot that this 'difficult' question was just 50p, lol. That's probably why it wasn't split. I think with all the solutions around a split of many points would've been nice ;-)

Was a nice exercise to play a bit with that grid, I never use it normally, but the principles of design, rendering and paint events apply just the same ;-)

One final thought: if you really want that kind of professional looking resizing that some browsers or adobe can do, you can mimic that by grabbing an image of the whole area and resizing that during the resize event. Once it finishes, you remove that overlay image and you use the standard method explained above.