473,785 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question on Controls and components

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

private System.Componen tModel.IContain er 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.A dd(this.comboBo x1);
this.Controls.A dd(this.menuStr ip1);

What's all this about?

Ta

Ray

Nov 1 '07 #1
7 1403
On Nov 1, 1:48 pm, RBrowning1...@g mail.com wrote:
here's an easy one for you guys - .NET form designer generates this:

private System.Componen tModel.IContain er 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 BackgroundWorke r 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.A dd(this.comboBo x1);
this.Controls.A dd(this.menuStr ip1);
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
Hi,
--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
<RB***********@ gmail.comwrote in message
news:11******** *************@d 55g2000hsg.goog legroups.com...
here's an easy one for you guys - .NET form designer generates this:

private System.Componen tModel.IContain er 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.A dd(this.comboBo x1);
this.Controls.A dd(this.menuStr ip1);
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
On Nov 1, 6:08 pm, Andy <an...@med-associates.comw rote:
On Nov 1, 1:48 pm, RBrowning1...@g mail.com wrote:
here's an easy one for you guys - .NET form designer generates this:
private System.Componen tModel.IContain er 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 BackgroundWorke r 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.A dd(this.comboBo x1);
this.Controls.A dd(this.menuStr ip1);

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
On Nov 1, 6:12 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions .comwrote:
Hi,

--
Ignacio Machinhttp://www.laceupsolut ions.com
Mobile & warehouse Solutions.<RBro wning1...@gmail .comwrote in message

news:11******** *************@d 55g2000hsg.goog legroups.com...
here's an easy one for you guys - .NET form designer generates this:
private System.Componen tModel.IContain er 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.A dd(this.comboBo x1);
this.Controls.A dd(this.menuStr ip1);

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
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
On Nov 2, 8:08 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions .comwrote:
Hi,

--
Ignacio Machinhttp://www.laceupsolut ions.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
On Nov 1, 6:12 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions .comwrote:
Hi,

--
Ignacio Machinhttp://www.laceupsolut ions.com
Mobile & warehouse Solutions.<RBro wning1...@gmail .comwrote in message

news:11******** *************@d 55g2000hsg.goog legroups.com...
here's an easy one for you guys - .NET form designer generates this:
private System.Componen tModel.IContain er 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.A dd(this.comboBo x1);
this.Controls.A dd(this.menuStr ip1);

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2979
by: Hal Vaughan | last post by:
I think a lot of this is definately a question of personal programming style, but I'm new to Java and would like to hear a few opinions. I'm writing a control panel for an application that runs separately. The control panel is basically (almost) fully self contained. It consists of a tabbed pane with 5 different tabs. Each tab has a number of different controls -- basically all the "commonly used" controls (buttons, lists, comboboxes,...
6
2541
by: Vanessa | last post by:
With this program I can do one selection, but upon the second I get an error where ///////////////// is indicated. Please help. using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data;
1
2841
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from remote server and display this info on the UI. From doing some research, I know that the way my implementation works today is not thread-safe, because essentially my worker thread updates the UI, which is BAD. So, here I am trying to figure out how...
10
3483
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read somewhere that each folder under the "web site" is compiled in separate assembly. I however, did not find that the "web site" creation in vs.net 2005 created any AssemblyInfo.cs file.
3
1590
by: Debbie Carter | last post by:
Can XML files be easily encrypted?
0
1625
by: Dave Coate | last post by:
I am working on a generic way to launch multiple similar processes (threads) at once, but limit the number of threads running at any one time to a number I set. As I understand it the following line makes a Queue "thread safe", so I do not need to explicitly lock and unlock it when multiple threads are working with it. 'Thread safe queue Private IndexQueue As Queue = Queue.Synchronized(New Queue)
8
3191
by: mark.norgate | last post by:
I've run into a few problems trying to use generics for user controls (classes derived from UserControl). I'm using the Web Application model rather than the Web Site model. The first problem I'm having is that the partial class signature in my projectDetails.ascx.cs file looks like this: public partial class ProjectDetailsControl<TEntryServiceProvider: UserControl, INamingContainer where TEntryServiceProvider : IEntryServiceProvider...
8
3590
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a picture box, lots of text boxes (for input).. you get the idea. All of a sudden everything on the form has disappeared, it looks like a blank, newly created form. I can still get to the properties of every item on the form using the drop-down box in...
1
2035
by: Martin | last post by:
Hi all ! I use Visual Studio .NET 2005 SP1 (+ Updates for Vista) on Windows Vista. I have a strange problem in a WinForm application. In a UserControl, which inherit another UserControl (simply contains a SplitterPanel), I've added controls (most of them are TextBox with the property Anchors set to Left and Right) to Panel2. All theses controls fits in the UserControl and when I resize it, all the controls have the correct behavior....
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9483
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10096
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.