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
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.
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.
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With