Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to load form with many controls Smooth on Winform? [duplicate]

Tags:

c#

winforms

I have a C# program with a DataGridView on the form.

When the user selects a row and presses a button, I present control panel with some textboxes that fill from the DataGridView.

When the control panel is shown, I see the controls building on the screen and it's not pleasing to the eye.

How do I show this control panel instantly?

Thanks in advance

like image 280
Gali Avatar asked Apr 12 '11 11:04

Gali


3 Answers

Control.SuspendLayout can be used to stop the control painting while you modify it and ResumeLayout when you are done

If the drawing is too slow you can finesse the control double buffering. Thanks to Sergio for the link.

like image 102
Jodrell Avatar answered Oct 20 '22 18:10

Jodrell


I had the same problem. I use BackgroundWorker on the the Load event handler of the form. That solved my problem.

private void MainForm_Load(object sender, EventArgs e)
{        
     backgroundWorker.RunWorkerAsync();
}

private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
     //Write here all the initial code that should be in the Load event handler.
}
like image 22
LEMUEL ADANE Avatar answered Oct 20 '22 16:10

LEMUEL ADANE


One of two situations are occurring:

Either: you have a very large number of controls on the panel.

Or: you are doing some other data loading in the middle of populating the panel.

For the first one, the easiest thing I know of to get the control handles going is to draw it off screen or behind another control and then reposition it when it's all ready.

For the second one, I'd create the panel first then connect the bindings / populate afterwards.

Without some sample code about how you create the panel and how you supply the data, I can only speculate.

like image 34
Adam Houldsworth Avatar answered Oct 20 '22 17:10

Adam Houldsworth