views:

122

answers:

3

Is there a way to turn off all visual updates to a .NET form while I am manipulating it? When my program first loads, for example, I set the tab control to the tab that was last open. The user can see the program switching tabs.

I have looked into SuspendLayout and ResumeLayout, but either I don't understand what they are doing, or I am not using them correctly, because they don't seem to have any effect. Someone told me that there used to be a way to turn off paint events in VB 6. Does this still exist in .NET?

+5  A: 

For the main window, the simplest thing to do is to create the window hidden, do all your things, and then show the window. This way you'll have one complete redraw, and some parts of the layout performed once.

OregonGhost
+1  A: 

Override OnPaint and OnPaintBackground in your form/control. When a flag is set, dont call the base implementation of the methods.

Other approach which will work with children link text

James Westgate
This should also work in situations beyond just the initial start-up.
Nate Bross
Does this work for all children as well?
OregonGhost
+1  A: 

There is an unmanaged approach that seems to work best (at least in my experience):

http://stackoverflow.com/questions/2682025/disable-painting-of-the-vscrollbar-in-a-system-windows-forms-richtextbox

The Question is about a Scrollbar but I used the approach with forms several times since I know how to do it. It doesn't matter what for a control is is unless you know the handle (Me.Handle)

SchlaWiener