Windows Develop Bookmark and Share   
 index > Windows Forms General > Listbox control
 

Listbox control

I've got a form with a listbox and a button to add an item to the listbox. Now in the VS2005 editor I've dragged the listbox onto the form. The thing is I would assume that the listbox would be part of the TaskList Class thatI have.

I assume if I'm programming full OO that the list box would be created in the class and not by me dragging the listbox onto the form? Am I correct?

I assume if its pure OO and the listbox methods add and subtract items from the listbox, that the listbox is part of the tasklist class and not the form?

Any guidance on this is appreciated. If I'm way off track please tell me.

Regards

fc

Leefri  Thursday, March 29, 2007 3:39 PM
You are possibly mixing up the notion of a class with a class instance (an object of a class). The ListBox class derives from the Control class, its declaration and implementation is contained within the System.Windows.Forms.dll assembly. When you drop a ListBox onto a form, the Designer creates a private member in the form of type System.Windows.Forms.ListBox. It does *not* create a new class, just an instance of a ListBox.

It might be helpful to see what the form Designer does. In the Solution Explorer, click the Show All Files icon. Open the node next to the form and double-click the Designer.cs file. Open the region marked "Windows Form Designer generated code". Check out how this code changes as you play with the designer.
nobugz  Saturday, March 31, 2007 6:52 PM

Friendlycoder:

after you drag list box you can see this.Listbox, then I think Listbox is already inyour class.

then the listbox is a member of form class.

I am not sure , since your list need appear at the form , why not put it in the form calss?

Bob zhu - SJTU  Friday, March 30, 2007 3:24 AM

It seems the most appropiate place within the form class; I just thought if I looked at it from a real world perspective, that the ListBox it would be in the other class, but I understand that ListBox inherits from Form Class (correct?), and if all my classes share the same namespace then it should be ok.

In a larger application would this still be the case? would you want to keep your form controls separate from the classes that they should be in?

Leefri  Friday, March 30, 2007 9:46 AM
You are possibly mixing up the notion of a class with a class instance (an object of a class). The ListBox class derives from the Control class, its declaration and implementation is contained within the System.Windows.Forms.dll assembly. When you drop a ListBox onto a form, the Designer creates a private member in the form of type System.Windows.Forms.ListBox. It does *not* create a new class, just an instance of a ListBox.

It might be helpful to see what the form Designer does. In the Solution Explorer, click the Show All Files icon. Open the node next to the form and double-click the Designer.cs file. Open the region marked "Windows Form Designer generated code". Check out how this code changes as you play with the designer.
nobugz  Saturday, March 31, 2007 6:52 PM
Thanks for that help; so everything I drop onto a form is then already defined, just not set as a class, meaning it cannot be used until you make it a class.
Leefri  Monday, April 02, 2007 7:55 AM

You can use google to search for other answers

Custom Search

More Threads

• toolstrip image system.drawing.bitmap
• Form TextBoxArray - retrieve values
• Forms app with BackgroundWorker consumes 100% cpu while working.
• Adding button dynamically to an existing control
• Strange Location Behaviour
• Activex Com control properties
• Stop button in the application...
• Deny MessageBox in WebBrowser Control
• multiple trhreads updating UI
• C# .net Force All Open Windows to close?