473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Initializing Components

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
Nov 17 '05 #1
3 2767
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]
- mv*@spam.guard.caspershouse.com

"pagates" <pa*****@discussions.microsoft.com> wrote in message
news:80**********************************@microsof t.com...
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

Nov 17 '05 #2
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"pagates" <pa*****@discussions.microsoft.com> wrote in message
news:80**********************************@microsof t.com...
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


Nov 17 '05 #3
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" wrote:
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"pagates" <pa*****@discussions.microsoft.com> wrote in message
news:80**********************************@microsof t.com...
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


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
14
by: Avi Uziel | last post by:
Hi All, I'm writing a Windows DLL which contain some utility classes. One of my classes is Singleton, therefore contain some static members. I'm using VC6 and linking to the DLL statically. ...
0
by: Brett | last post by:
I'm trying to use an ActiveX control that works fine in VB.NET but not in C#. The VB projects places the ActiveX control on a form. The C# project doesn't because the control is used in a non...
8
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
38
by: junky_fellow | last post by:
Guys, I was just looking at some code where to initialize an integer with all F's following statement is used; unsigned int i = -1; I want to know if this is the right way of doing the...
1
by: RDalal | last post by:
Hi, I am developing a program in VB.NET and I have a form in which I have about 25 components (including textboxes, comboboxes, checkboxes etc.) In the begining of my code I need to initialize all of...
10
by: Jason Doucette | last post by:
Situation: I have a simple struct that, say, holds a color (R, G, and B). I created my own constructors to ease its creation. As a result, I lose the default constructor. I dislike this, but...
13
by: WaterWalk | last post by:
Hello. When I consult the ISO C++ standard, I notice that in paragraph 3.6.2.1, the standard states: "Objects with static storage duration shall be zero-initialized before any other...
6
by: Jai Prabhu | last post by:
Hi All, Consider the following piece of code: void func (void) { static unsigned char arr = "\x00\xAA\xBB"; fprintf (stderr, "0x%x\n", arr); fprintf (stderr, "0x%x\n", arr);
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.