Initializing Components

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello All,

When creating a Windows Forms UserControl, is there any way to tell if its
container is in the midst of its InitializeComponent call, other than setting
a property?

For instance, say I have a control called SomeControl that contains some
properties Property1, Property2, ..., PropertyN. Each of these properties
may do something time consuming, like accessing a database or updating UI,
etc. The constructor may set up some default stuff.

Then, I have a test container that does something like:

private void InitializeComponent()
{
this.MySomeControl = new SomeControl();

// Initialize some other stuff
// |

//
// MyUTM
//
this.MySomeControl.BackColor = System.Drawing.SystemColors.Control;
this.MySomeControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.MySomeControl.Property1 = "SomeHostName";
this.MySomeControl.Property2 = "MyUserName";
// more properties
this.MySomeControl.PropertyN = Colors.Red;
this.MySomeControl.Location = new System.Drawing.Point(0, 0);
this.MySomeControl.Name = "SomeControl";
this.MySomeControl.Size = new System.Drawing.Size(760, 566);
this.MySomeControl.TabIndex = 8;
}

Is there any way to prevent the processing of all the properties until the
test client is done initializing? I don't want to process Property1, then
Property2, then PropertyN - instead I want to process PropertyN only.

Thanks,
pagates
 
pagates,

Your control should implement the ISupportInitialize interface. The
designer should pick up on this, and make a call to BeginInit and EndInit to
indicate when batches of properties are being set.

Hope this helps.
 
Hi Nicholas,

Thanks for that information.

Does this work with VS 2003? I've added the implementation, and see the
events (simply by putting in a MessageBox), but I don't see any changes in
InitializeComponent call that uses this control.

The control in question is used in another UserControl - does that make a
difference?

Thanks,
Paul

Nicholas Paldino said:
pagates,

Your control should implement the ISupportInitialize interface. The
designer should pick up on this, and make a call to BeginInit and EndInit to
indicate when batches of properties are being set.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

pagates said:
Hello All,

When creating a Windows Forms UserControl, is there any way to tell if its
container is in the midst of its InitializeComponent call, other than
setting
a property?

For instance, say I have a control called SomeControl that contains some
properties Property1, Property2, ..., PropertyN. Each of these properties
may do something time consuming, like accessing a database or updating UI,
etc. The constructor may set up some default stuff.

Then, I have a test container that does something like:

private void InitializeComponent()
{
this.MySomeControl = new SomeControl();

// Initialize some other stuff
// |

//
// MyUTM
//
this.MySomeControl.BackColor = System.Drawing.SystemColors.Control;
this.MySomeControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.MySomeControl.Property1 = "SomeHostName";
this.MySomeControl.Property2 = "MyUserName";
// more properties
this.MySomeControl.PropertyN = Colors.Red;
this.MySomeControl.Location = new System.Drawing.Point(0, 0);
this.MySomeControl.Name = "SomeControl";
this.MySomeControl.Size = new System.Drawing.Size(760, 566);
this.MySomeControl.TabIndex = 8;
}

Is there any way to prevent the processing of all the properties until the
test client is done initializing? I don't want to process Property1, then
Property2, then PropertyN - instead I want to process PropertyN only.

Thanks,
pagates
 
Whoops! Never mind - I found the correct calls.

I was looking for them in the section that initialized the properties of
that control.

"I'll learn that .NET stuff yet!"

Thanks again,
pagates


pagates said:
Hi Nicholas,

Thanks for that information.

Does this work with VS 2003? I've added the implementation, and see the
events (simply by putting in a MessageBox), but I don't see any changes in
InitializeComponent call that uses this control.

The control in question is used in another UserControl - does that make a
difference?

Thanks,
Paul

Nicholas Paldino said:
pagates,

Your control should implement the ISupportInitialize interface. The
designer should pick up on this, and make a call to BeginInit and EndInit to
indicate when batches of properties are being set.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

pagates said:
Hello All,

When creating a Windows Forms UserControl, is there any way to tell if its
container is in the midst of its InitializeComponent call, other than
setting
a property?

For instance, say I have a control called SomeControl that contains some
properties Property1, Property2, ..., PropertyN. Each of these properties
may do something time consuming, like accessing a database or updating UI,
etc. The constructor may set up some default stuff.

Then, I have a test container that does something like:

private void InitializeComponent()
{
this.MySomeControl = new SomeControl();

// Initialize some other stuff
// |

//
// MyUTM
//
this.MySomeControl.BackColor = System.Drawing.SystemColors.Control;
this.MySomeControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.MySomeControl.Property1 = "SomeHostName";
this.MySomeControl.Property2 = "MyUserName";
// more properties
this.MySomeControl.PropertyN = Colors.Red;
this.MySomeControl.Location = new System.Drawing.Point(0, 0);
this.MySomeControl.Name = "SomeControl";
this.MySomeControl.Size = new System.Drawing.Size(760, 566);
this.MySomeControl.TabIndex = 8;
}

Is there any way to prevent the processing of all the properties until the
test client is done initializing? I don't want to process Property1, then
Property2, then PropertyN - instead I want to process PropertyN only.

Thanks,
pagates
 
Back
Top