开发者

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

This question already has an answer here: 开发者_如何学Go Winforms Double Buffering (1 answer) Closed 5 years ago.

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.


I have faced the same issue, thanks to "Adam Houldsworth" answer [SOLVED] :

1- position all controls that contain all other controls to some position out of screen.

Say, to (2000, 2000)

2- make them inVisible (try, someControl.Visible = false)

3- on Form_Shown event :

  • return the controls you move to their actual locations
  • make them Visible (try, someControl.Visible = true)

it was satisfied and much better.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜