Addressing ComponentTray Objects

  • Thread starter Thread starter Michael Maes
  • Start date Start date
M

Michael Maes

Hello,

I wan't to address ComponentTray Objects such as Timers, NotifyIcons, ContextMenus, ..., in short: objects that don't belong to the Forms' ControlCollection.

The trick is I want to do this not knowing (in design-time) whether they will exist on "a" form, even worse, not knowing their name at all (but knowing their class).

Let's say, as example, that I have an MDI-Application and that all forms are inherited from "a" BaseForm (which in turn inherits from System.Windows.Forms.Form) which has extended methods, events & properties.
One of the things the BaseForm does is (eg) adding a MenuItem to a ContextMenu. Now the BaseForm doesn't 'know' if there will be a ContextMenu, nor what it's name will be.

With "normal" controls I just perform a recursive scan through the Forms' ControlCollection (upon instantiation) and I put the controls in a HashTable.

With ComponentTray Objects, this trick won't work because they do not belong to the Forms' ControlCollection.

I guess that this "smells like" Reflection, but I haven't had the time to get into that (yet).

Any suggestion would be highly appreciated,

I work with vb.NET (but cs.NET I equally welcome)

Michael

PS: I'll be out of office till saturday, so I won't be able to react before sunday.

TIA
 
Hi Michael,

Regarding the question, ContextMenu is different from others. It can only
be displayed at runtime and accessed by the owner who call its show method.
For other components likeTimer and NotifyIcon, we can access from
System.Windows.Forms.Form's components property. For example:

Dim cc As System.ComponentModel.Component

For Each cc In Me.components.Components
MsgBox(cc.ToString)

Next

With above code, you will get all components's class added below the form.

Hope this help,



Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hi Luke,

Thanks alot. This-one already helps me verry much.
I've noticed however that DataSets (and maybe other components) don't belong
to the Components'collection.
Is there a similar trick to address those?

TIA,

Michael
 
Hi Michael,

The DataSet in the component Tray is just like internal variant we defined
at runtime: Dim ds as DataSet. We can't enumerate from a collection. (No
such collection in winform's property).

Regards,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top