all groups > dotnet windows forms designtime > june 2004 >
You're in the

dotnet windows forms designtime

group:

Component Tray


Re: Component Tray Frank Hileman
6/17/2004 8:51:38 AM
dotnet windows forms designtime:
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

[quoted text, click to view]

Component Tray Don Munroe
6/17/2004 9:28:28 AM
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

Re: Component Tray draiko NO[at]SPAM rhenus.de
6/18/2004 12:34:03 AM
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

[quoted text, click to view]
AddThis Social Bookmark Button