By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,289 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,289 IT Pros & Developers. It's quick & easy.

Question on Controls and components

P: n/a
here's an easy one for you guys - .NET form designer generates this:

private System.ComponentModel.IContainer components = null;

but I don't see it used anywhere in the generated code - what's all
that about? Also, it generates code to add the individual controls to
Controls as in:

this.Controls.Add(this.comboBox1);
this.Controls.Add(this.menuStrip1);

What's all this about?

Ta

Ray

Nov 1 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Nov 1, 1:48 pm, RBrowning1...@gmail.com wrote:
here's an easy one for you guys - .NET form designer generates this:

private System.ComponentModel.IContainer components = null;

but I don't see it used anywhere in the generated code - what's all
that about?
There are non-visual units of code called Components that can be
modified in the designer. These will appear in the Component tray of
the form designer. Try adding a BackgroundWorker component to a form;
its not a visual control, but you can still set it up via the
designer.
Also, it generates code to add the individual controls to
Controls as in:

this.Controls.Add(this.comboBox1);
this.Controls.Add(this.menuStrip1);
The designer isn't magic; its just a code generation tool. if you
didn't have the designer to work with, that's how you would create
controls and place them on the form. this refers to the Form instance
and it has a Controls collection. The form needs to know about the
controls which are placed on it for various reasons, and the control
needs to know what is containing it. That's all that code is doing.
If you fail to have those lines, you'll never see the control, but it
doesn't know what it should be painting itself on.

HTH
Andy

Nov 1 '07 #2

P: n/a
Hi,
--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
<RB***********@gmail.comwrote in message
news:11*********************@d55g2000hsg.googlegro ups.com...
here's an easy one for you guys - .NET form designer generates this:

private System.ComponentModel.IContainer components = null;
This line most of the time looks like that and has no use, no idea why it's
still generated.
but I don't see it used anywhere in the generated code - what's all
that about? Also, it generates code to add the individual controls to
Controls as in:

this.Controls.Add(this.comboBox1);
this.Controls.Add(this.menuStrip1);
That code is NEEDED, it does include the controls inside the Controls
collection (or either the form or to another container control) If you do
not do that the control is not displayed ni the screen.
Nov 1 '07 #3

P: n/a
On Nov 1, 6:08 pm, Andy <an...@med-associates.comwrote:
On Nov 1, 1:48 pm, RBrowning1...@gmail.com wrote:
here's an easy one for you guys - .NET form designer generates this:
private System.ComponentModel.IContainer components = null;
but I don't see it used anywhere in the generated code - what's all
that about?

There are non-visual units of code called Components that can be
modified in the designer. These will appear in the Component tray of
the form designer. Try adding a BackgroundWorker component to a form;
its not a visual control, but you can still set it up via the
designer.
Also, it generates code to add the individual controls to
Controls as in:
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.menuStrip1);

The designer isn't magic; its just a code generation tool. if you
didn't have the designer to work with, that's how you would create
controls and place them on the form. this refers to the Form instance
and it has a Controls collection. The form needs to know about the
controls which are placed on it for various reasons, and the control
needs to know what is containing it. That's all that code is doing.
If you fail to have those lines, you'll never see the control, but it
doesn't know what it should be painting itself on.

HTH
Andy
Thanks for the reply. I know about compoents - if I add them to the
form they are not added to the components container tho....the
Controls thing appears to be for children. Ta Ray

Nov 1 '07 #4

P: n/a
On Nov 1, 6:12 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
Hi,

--
Ignacio Machinhttp://www.laceupsolutions.com
Mobile & warehouse Solutions.<RBrowning1...@gmail.comwrote in message

news:11*********************@d55g2000hsg.googlegro ups.com...
here's an easy one for you guys - .NET form designer generates this:
private System.ComponentModel.IContainer components = null;

This line most of the time looks like that and has no use, no idea why it's
still generated.
but I don't see it used anywhere in the generated code - what's all
that about? Also, it generates code to add the individual controls to
Controls as in:
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.menuStrip1);

That code is NEEDED, it does include the controls inside the Controls
collection (or either the form or to another container control) If you do
not do that the control is not displayed ni the screen.
Thanks for this reply. Controls appears to be used for controls'
children - if you add a group box foe ex. and add controls to the
groupbox then they are added to the groupbox's controls. All clear on
that. U say that Components is not used - and I haven't sen it used
either. Other systems (such as Delphi) also keep a list of owned
components - things that need to be dsestroyed - I would have thought
componets would be used for that but there's no concept of ownership
in the framewok is there 'cos of GC I suspect. Ta Ray

Nov 1 '07 #5

P: n/a
Hi,
--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Thanks for this reply. Controls appears to be used for controls'
children - if you add a group box foe ex. and add controls to the
groupbox then they are added to the groupbox's controls. All clear on
that. U say that Components is not used - and I haven't sen it used
either. Other systems (such as Delphi) also keep a list of owned
components - things that need to be dsestroyed - I would have thought
componets would be used for that but there's no concept of ownership
in the framewok is there 'cos of GC I suspect. Ta Ray
I think that the need to having a list of Components is cause they implement
IDisposable, so the Form's dispose can call all the dispose methods of these
components.

Nov 2 '07 #6

P: n/a
On Nov 2, 8:08 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
Hi,

--
Ignacio Machinhttp://www.laceupsolutions.com
Mobile & warehouse Solutions.
Thanks for this reply. Controls appears to be used for controls'
children - if you add a group box foe ex. and add controls to the
groupbox then they are added to the groupbox's controls. All clear on
that. U say that Components is not used - and I haven't sen it used
either. Other systems (such as Delphi) also keep a list of owned
components - things that need to be dsestroyed - I would have thought
componets would be used for that but there's no concept of ownership
in the framewok is there 'cos of GC I suspect. Ta Ray

I think that the need to having a list of Components is cause they implement
IDisposable, so the Form's dispose can call all the dispose methods of these
components.
HI there - I see how the Dispose method uses components - and your
suggestion sounds correct in that it's to with impleemnting Dispose -
I'm just not sure how things get added to it?

Ta

Ray

Nov 2 '07 #7

P: n/a
On Nov 1, 6:12 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
Hi,

--
Ignacio Machinhttp://www.laceupsolutions.com
Mobile & warehouse Solutions.<RBrowning1...@gmail.comwrote in message

news:11*********************@d55g2000hsg.googlegro ups.com...
here's an easy one for you guys - .NET form designer generates this:
private System.ComponentModel.IContainer components = null;

This line most of the time looks like that and has no use, no idea why it's
still generated.
but I don't see it used anywhere in the generated code - what's all
that about? Also, it generates code to add the individual controls to
Controls as in:
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.menuStrip1);

That code is NEEDED, it does include the controls inside the Controls
collection (or either the form or to another container control) If you do
not do that the control is not displayed ni the screen.
<<This line most of the time looks like that and has no use, no idea
why it's
still generated.>>
Just figured this out - it's to do with compoents with a specific type
of consturctor - add an imagelist to the form for example and it's
used.

Nov 5 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.