Locating non-UI components on form

G

Gerrit

Hi.

I'm looking for a way to programmatically find and access at run-time any
controls that are placed on the "component tray" area on a form (such as
ImageLists). The Form.Controls collection is of no use as it does not
contain any controls that are not placed on the form itself.


Gerrit
 
B

Bob Powell [MVP]

You could use reflection to read the fields of the object and get their
types. If they're based on Component and not Control they probably show up
in the tray.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Gerrit,

Components that appear in the tray are put in the
System.ComponentModel.Container components collection. Provate member that
VS.NET adds when starting a new form. This collection is not part of the
hierarchy and it is not inhertied from the parent. That means that in your
form's componets collection you won't find any components that has been
added in the base form. The collection is private that means it can be
accessed only form the form's code, unless refelection is not used. And the
last think is unlike Controls collection where you'll find any control which
is added at design or run time components don't have to be in that
collection. However if a component appears in the component tray it is
there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top