Problem placing components on inherited forms

  • Thread starter Thread starter Markus
  • Start date Start date
M

Markus

Hello,

I am trying to create a custom control which inherits from
System.Windows.Forms.Form and can be used as a base class
for an application. So far so good.

I am also writing custom components which inherit from
System.ComponentModel.Component.

What I would like to know is if there is any way for my
custom form class can be made aware of these components?

The problem is that when my form class is instantiated at
design time via "Add Inherited Form" and I drop a
component on this form, the designer automagically extends
the base class by adding an IContainer
called "components". The component is then added to this
collection.

Is there any reasonably simple way to get these components
to act like controls and drop themselves into a nice
collection of my choosing? I also need the reverse link -
from component to form i.e. something comparable to the
Parent property of controls.

Thanks for all help.
Sincerely,
Markus

PS - for more background info, I started a thread on Aug.
19th '03 re: "How-to create user control replacing..."
 
Not sure why I'm talking to myself here, but thought I
would follow up again -

Found a solution for the parent form to child component
link as well. Instead of using the Container class, I
switched to the ArrayList class. Works just fine (although
I still need to implement the code which would test it at
design time, I know it works fine at runtime).

So to recap, if this ever makes it to a reference list
like dotnet247, if you need to double-link components and
custom forms, you can do the component to form link by
overriding the Site property (see code sample in my
previous post). Assuming you declare a component property
Parent, the code in Site property can automatically link
the component to the parent form and the IDE will
automatically put the link in the form code it generates.

To make the reverse link, declare an ArrayList in the
custom form and add methods which will add and remove
objects from it. Finally, add code to the set method of
the component's Parent property which will call these
remove/add methods whenever the property is altered
(probably should also add a call when the component is
disposed).

Both links should be valid at both design time and run
time (after the component is initialized).

Markus
 
Back
Top