Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / June 2004

Tip: Looking for answers? Try searching our database.

Component Tray

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Don Munroe - 17 Jun 2004 14:28 GMT
Hello all,

   I've searched around and can't seem to find a solution to this.  I have
a component that builds a tree of controls / components that are placed on a
form.  The walking the controls was easy and is working great.  The problem
is the components in the ComponentTray.  I've added multiple Save File
Dialogs, Open File Dialogs, Font Dialogs, etc...

   When I create an instance of the component tray, the only component
listed is my custom component because I added a constructor that takes
IContainer as a parameter.

   Does anyone have any idea how I can get the list of components in the
ComponentTray regardless of whether or not it has a IContainer constructor.

   I've also found out that the components name property isn't available at
run time, this could lead to other problems, so if any one has an idea for
that it would be greatly appreciated.

Don Munroe
Frank Hileman - 17 Jun 2004 16:51 GMT
Hello Don,

You wish to obtain this information at design-time, correct? At run-time
there is no reliable way to obtain this information. There is no way to
obtain the name either, if it is not serialized as a property in the
Component, as with Control. The only way to do this is via reflection on
members, and you are making a lot of assumptions if you start doing that.
That is, which fields were added by the designer, and which fields were
added outside the designer? How can you know?

If all your Component-derived classes have a Name property, then it will be
used both at design and run-time, and will be serialized and available at
run-time. But you cannot change classed created by other authors, to force
them to serialize a name.

At design-time, if you derive from Component you have a Container property
that should list all components known to the root designer. That includes
controls as well as components in the component tray.

Regards,
Frank Hileman

check out VG.net: www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

> Hello all,
>
[quoted text clipped - 16 lines]
>
> Don Munroe
DRaiko - 18 Jun 2004 08:34 GMT
Hello Don,

if you really need component names at runtime, an easier way (no assumptions
about components created by other authors) is to subclass the containing
form and support some kind of dictionary {ComponentName -> Pointer} in it.

You can serialize the dictionary and thus use it at runtime. At design time
Component-Added/Removed/Rename must be handled. You can even recreate
the dictionary in EndInit() of the form or when the form is persisted.
(More reliable, since it can happen that components are
added/removed/renamed "manually" editing the text and no Component* event
will imform you about this.)
It works (i have had the same problem).

HTH,
dima

> Hello Don,
>
[quoted text clipped - 47 lines]
> >
> > Don Munroe

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.