Home All Groups Group Topic Archive Search About

Manually adding usercontrol to panel on form

Author
29 Jun 2005 8:02 AM
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
Author
29 Jun 2005 2:09 PM
Jim Hughes
<tonny.st***@invenia.no> wrote in message
Show quoteHide quote
news:1120031698.535131.31210@f14g2000cwb.googlegroups.com...
>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

Bookmark and Share