Manually adding usercontrol to panel on form

T

tonny.steen

I wonder if there is a way to have a flicker free initial paint of a
usercontrol on a panel (on a form) when done manually. My usercontrol
with many controls is first painted in its origional size, then resized
to fit the host panel (docked). This is not nice to look at since the
initial load/paint of the usercontrol is slow. So, my question is:

Is there a way to first have it resized then painted?

Code snipet from form (start):
private UserControl currentUserControl;

private void button1_Click(object sender, System.EventArgs e)
{
if (this.currentUserControl != null)
{
this.panel1.Controls.Remove(currentUserControl);
this.currentUserControl = null;
}
this.currentUserControl = new UserControl1();
this.currentUserControl.Name = "currentUserControl";
this.panel1.Controls.Add(currentUserControl);
this.panel1.Controls[0].Dock = DockStyle.Fill;
this.currentUserControl.Visible = true;
}
Code snipet (end):

- Tonny
 
J

Jim Hughes

I wonder if there is a way to have a flicker free initial paint of a
usercontrol on a panel (on a form) when done manually. My usercontrol
with many controls is first painted in its origional size, then resized
to fit the host panel (docked). This is not nice to look at since the
initial load/paint of the usercontrol is slow. So, my question is:

Is there a way to first have it resized then painted?

Code snipet from form (start):
private UserControl currentUserControl;

private void button1_Click(object sender, System.EventArgs e)
{
if (this.currentUserControl != null)
{
this.panel1.Controls.Remove(currentUserControl);
this.currentUserControl = null;
}
this.currentUserControl = new UserControl1();
this.currentUserControl.Name = "currentUserControl";
this.panel1.Controls.Add(currentUserControl);
this.panel1.Controls[0].Dock = DockStyle.Fill;
this.currentUserControl.Visible = true;
}
Code snipet (end):

Perhaps it might work better if you wrap it in SuspendLayout / ResumeLayout
calls
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top