Fliker and UserControl

M

Martin

Hi !

I've developed a small UserControl with five textbox and label.
However, when I want to display the UserControl in a form, controls
appear slowly one after one. I've activated double buffering and
removed all code in the OnLoad, constructor and I still have the same
problem.
Here is the code that I use to display the UserControl un the form

_objContainer.SuspendLayout();
_objContainer.Controls.Clear();
_objContainer.Controls.Add(_objUserControl);
_objContainer.ResumeLayout(false);

How can I resolve this problem? Thanks for your help!

Martin
 
M

Martin

Hi!

Here some important part of the code in the UserControl... Thanks for
your help ! Maybe it's because I use a TableLayoutPanel ?

public AddressUC()
{
this.SetStyle(
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer, true);

InitializeComponent();
}

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.tableLayoutPanel1 = new
System.Windows.Forms.TableLayoutPanel();
this.txtStreet = new System.Windows.Forms.TextBox();
this.txtCity = new System.Windows.Forms.TextBox();
this.ddlState = new
EmpireOne.ClearSky.Presentation.Controls.ComboBoxState();
this.ddlCountry = new
EmpireOne.ClearSky.Presentation.Controls.ComboBoxCountry();
this.txtPostalCode = new System.Windows.Forms.TextBox();
this.lblStreet = new System.Windows.Forms.Label();
this.lblCity = new System.Windows.Forms.Label();
this.lblStateProvince = new System.Windows.Forms.Label();
this.lblPostalCode = new System.Windows.Forms.Label();
this.lblCountry = new System.Windows.Forms.Label();
this.errorProvider = new
System.Windows.Forms.ErrorProvider(this.components);
this.tableLayoutPanel1.SuspendLayout();

((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.Anchor =
((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new
System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute,
100F));
this.tableLayoutPanel1.ColumnStyles.Add(new
System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent,
100F));
this.tableLayoutPanel1.ColumnStyles.Add(new
System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent,
100F));
this.tableLayoutPanel1.ColumnStyles.Add(new
System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent,
100F));
this.tableLayoutPanel1.ColumnStyles.Add(new
System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent,
100F));
this.tableLayoutPanel1.ColumnStyles.Add(new
System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent,
100F));
this.tableLayoutPanel1.ColumnStyles.Add(new
System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent,
100F));
this.tableLayoutPanel1.ColumnStyles.Add(new
System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent,
100F));
this.tableLayoutPanel1.ColumnStyles.Add(new
System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent,
100F));
this.tableLayoutPanel1.Controls.Add(this.txtStreet, 1, 2);
this.tableLayoutPanel1.Controls.Add(this.txtCity, 1, 3);
this.tableLayoutPanel1.Controls.Add(this.ddlState, 1, 4);
this.tableLayoutPanel1.Controls.Add(this.ddlCountry, 1, 1);
this.tableLayoutPanel1.Controls.Add(this.txtPostalCode, 1,
5);
this.tableLayoutPanel1.Controls.Add(this.lblStreet, 0, 2);
this.tableLayoutPanel1.Controls.Add(this.lblCity, 0, 3);
this.tableLayoutPanel1.Controls.Add(this.lblStateProvince,
0, 4);
this.tableLayoutPanel1.Controls.Add(this.lblPostalCode, 0,
5);
this.tableLayoutPanel1.Controls.Add(this.lblCountry, 0, 1);
this.tableLayoutPanel1.Location = new
System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Margin = new
System.Windows.Forms.Padding(0, 3, 0, 3);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 6;
this.tableLayoutPanel1.RowStyles.Add(new
System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute,
15F));
this.tableLayoutPanel1.RowStyles.Add(new
System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new
System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new
System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new
System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new
System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.Size = new System.Drawing.Size(618,
165);
this.tableLayoutPanel1.TabIndex = 0;
//
// txtStreet
//
this.txtStreet.Dock = System.Windows.Forms.DockStyle.Fill;
this.errorProvider.SetIconAlignment(this.txtStreet,
System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
this.txtStreet.Location = new System.Drawing.Point(103,
45);
this.txtStreet.MinimumSize = new System.Drawing.Size(4,
26);
this.txtStreet.Multiline = true;
this.txtStreet.Name = "txtStreet";
this.txtStreet.ScrollBars =
System.Windows.Forms.ScrollBars.Vertical;
this.txtStreet.Size = new System.Drawing.Size(512, 32);
this.txtStreet.TabIndex = 1;
//
// txtCity
//
this.txtCity.Dock = System.Windows.Forms.DockStyle.Fill;
this.errorProvider.SetIconAlignment(this.txtCity,
System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
this.txtCity.Location = new System.Drawing.Point(103, 83);
this.txtCity.Name = "txtCity";
this.txtCity.Size = new System.Drawing.Size(512, 20);
this.txtCity.TabIndex = 2;
//
// ddlState
//
this.ddlState.Dock = System.Windows.Forms.DockStyle.Fill;
this.ddlState.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.ddlState.FormattingEnabled = true;
this.errorProvider.SetIconAlignment(this.ddlState,
System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
this.ddlState.Location = new System.Drawing.Point(103,
109);
this.ddlState.Name = "ddlState";
this.ddlState.Size = new System.Drawing.Size(512, 21);
this.ddlState.TabIndex = 3;
//
// ddlCountry
//
this.ddlCountry.ComboBoxState = this.ddlState;
this.ddlCountry.Dock = System.Windows.Forms.DockStyle.Fill;
this.ddlCountry.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.ddlCountry.FormattingEnabled = true;
this.errorProvider.SetIconAlignment(this.ddlCountry,
System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
this.ddlCountry.Location = new System.Drawing.Point(103,
18);
this.ddlCountry.Name = "ddlCountry";
this.ddlCountry.Size = new System.Drawing.Size(512, 21);
this.ddlCountry.TabIndex = 0;
//
// txtPostalCode
//
this.txtPostalCode.Dock =
System.Windows.Forms.DockStyle.Fill;
this.errorProvider.SetIconAlignment(this.txtPostalCode,
System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
this.txtPostalCode.Location = new System.Drawing.Point(103,
136);
this.txtPostalCode.Name = "txtPostalCode";
this.txtPostalCode.Size = new System.Drawing.Size(512, 20);
this.txtPostalCode.TabIndex = 4;
//
// lblStreet
//
this.lblStreet.AutoSize = true;
this.lblStreet.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblStreet.ImeMode =
System.Windows.Forms.ImeMode.NoControl;
this.lblStreet.Location = new System.Drawing.Point(3, 42);
this.lblStreet.Name = "lblStreet";
this.lblStreet.Size = new System.Drawing.Size(94, 38);
this.lblStreet.TabIndex = 0;
this.lblStreet.Text = "lblStreet";
this.lblStreet.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// lblCity
//
this.lblCity.AutoSize = true;
this.lblCity.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblCity.ImeMode =
System.Windows.Forms.ImeMode.NoControl;
this.lblCity.Location = new System.Drawing.Point(3, 80);
this.lblCity.Name = "lblCity";
this.lblCity.Size = new System.Drawing.Size(94, 26);
this.lblCity.TabIndex = 0;
this.lblCity.Text = "lblCity";
this.lblCity.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// lblStateProvince
//
this.lblStateProvince.AutoSize = true;
this.lblStateProvince.Dock =
System.Windows.Forms.DockStyle.Fill;
this.lblStateProvince.ImeMode =
System.Windows.Forms.ImeMode.NoControl;
this.lblStateProvince.Location = new
System.Drawing.Point(3, 106);
this.lblStateProvince.Name = "lblStateProvince";
this.lblStateProvince.Size = new System.Drawing.Size(94,
27);
this.lblStateProvince.TabIndex = 0;
this.lblStateProvince.Text = "lblStateProvince";
this.lblStateProvince.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// lblPostalCode
//
this.lblPostalCode.AutoSize = true;
this.lblPostalCode.Dock =
System.Windows.Forms.DockStyle.Fill;
this.lblPostalCode.ImeMode =
System.Windows.Forms.ImeMode.NoControl;
this.lblPostalCode.Location = new System.Drawing.Point(3,
133);
this.lblPostalCode.Name = "lblPostalCode";
this.lblPostalCode.Size = new System.Drawing.Size(94, 32);
this.lblPostalCode.TabIndex = 0;
this.lblPostalCode.Text = "lblPostalCode";
this.lblPostalCode.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// lblCountry
//
this.lblCountry.AutoSize = true;
this.lblCountry.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblCountry.ImeMode =
System.Windows.Forms.ImeMode.NoControl;
this.lblCountry.Location = new System.Drawing.Point(3, 15);
this.lblCountry.Name = "lblCountry";
this.lblCountry.Size = new System.Drawing.Size(94, 27);
this.lblCountry.TabIndex = 0;
this.lblCountry.Text = "lblCountry";
this.lblCountry.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// errorProvider
//
this.errorProvider.ContainerControl = this;
//
// AddressUC
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F,
13F);
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.tableLayoutPanel1);
this.DoubleBuffered = true;
this.Name = "AddressUC";
this.Size = new System.Drawing.Size(618, 176);
this.HandleDestroyed += new
System.EventHandler(this.AddressUC_HandleDestroyed);
this.Load += new System.EventHandler(this.AddressUC_Load);
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel1.PerformLayout();

((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
this.ResumeLayout(false);

}
 
D

Dave Sexton

Hi Martin,

You haven't posted enough code for me to reproduce the issue, but you
shouldn't just go ahead and post the rest of it either. You should try to
reduce the problem as much as possible by removing controls and code until
the problem goes away or the UserControl is at its simplest yet, and if you
haven't figured it out by then, post a short but complete sample (see Jon
Skeet's article for guidance:
http://www.yoda.arachsys.com/csharp/complete.html).

In the code you have posted you haven't included some things that may very
well be the cause of your issue. I can't reproduce the following:

1. HandleDestroyed event handler code
2. Load event handler code
3. ddlState custom control
4. ddlCountry custom UserControl
5. ddlCountry.ComboBoxState = ddlState

In VS 2005, I placed your code in an empty UserControl without the event
handlers and I changed both ddlState and ddlCountry to be normal ComboBox
controls (also removing the assignment of ddlState to the
ddlCountry.ComboBoxState property). I placed the control on an empty Form
and showed it at the start of the application. The control loaded fine.

To debug this problem, try removing all five of the above points first and
see if the problem goes away, add each back again one at a time until you
can narrow down the problem.

HTH
 

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