Can "InitializeComponent()" info be captured

  • Thread starter Thread starter Larry Smith
  • Start date Start date
L

Larry Smith

Hi there,

Don't know if I picked the correct NGs or not but maybe someone can steer me
in the right direction. Does anyone know if a class exists to capture the
same info now wrapped in "InitializeComponent()". I want to capture all form
details for a given form at design time (properties and controls) but I
can't find anyway to do it. Note that reading a form's ".resx" files won't
do either (it's only good for localized forms but in any case, it doesn't
always provide complete info). Thanks very much.
 
Larry,

At design time, you should hook into the designer. I would recommend
creating a component/control that you place on your form/control, and then
traversing the designer heiarchy (there is an object/interface model
specifically for this).

Check out the article in MSDN mag titled "Building Windows Forms
Controls and Components with Rich Design-Time Features", located at (watch
for line wrap):

http://msdn.microsoft.com/msdnmag/issues/03/04/Design-TimeControls/default.aspx

It has a section on the interfaces implemented by controls at design
time, and how you can access services of the designer and other information
about other components in the designer. Of course, it will probably involve
a good deal of reflection ony your part as well, unless you know what you
are looking for specifically.

Hope this helps.
 
Larry,
At design time, you should hook into the designer. I would recommend
creating a component/control that you place on your form/control, and then
traversing the designer heiarchy (there is an object/interface model
specifically for this).

Check out the article in MSDN mag titled "Building Windows Forms
Controls and Components with Rich Design-Time Features", located at (watch
for line wrap):

http://msdn.microsoft.com/msdnmag/issues/03/04/Design-TimeControls/default.aspx

It has a section on the interfaces implemented by controls at design
time, and how you can access services of the designer and other
information about other components in the designer. Of course, it will
probably involve a good deal of reflection ony your part as well, unless
you know what you are looking for specifically.

Thanks very much. I'll look into it. It seems however that there's no (easy)
way for developers to extract a form from a project after the fact. Unlike
in raw Windows programming for instance, where an entire dialog can be
extracted from its ".res" file (or even it's corresponding ".rc" source
file) , no analogue seems to exist in .NET. A simple collection class
exposing all forms in a project (their properties and controls) is all
that's required. I'm surprised that this doesn't already exist but have
already suggested it to MSFT product feedback. Anyway, thanks again.
 
Larry,

You can always load already compiled assembly reflect on it, find all public
forms and/or user controls, create the object and then go through their
Controls collections. This will give you pretty good information on the
structure of the forms and user controls in an assembly.
 
Larry,
You can always load already compiled assembly reflect on it, find all
public forms and/or user controls, create the object and then go through
their Controls collections. This will give you pretty good information on
the structure of the forms and user controls in an assembly.

Thanks for the reply. Unfortunately it's not so simple :)
This app will be running on unknown 3rd-party developer machines. Therefore,
if the programmer adds any code immediately after the call to
"InitializeComponent()" (to initialize the form normally) then:

1) It may not run on the developer's machine where this is all taking place
(if the code depends on resources found in the actual release environment)
2) I can't allow this code to run anyway since I have no idea what it does
(therefore subject to failure, potentially very slow or even dangerous,
etc.)
3) I only want to capture the basic form without initializing its controls
in anyway (granted, if any controls or properties are manually added/changed
then I have a problem)

Anyway, thanks again.
 
Back
Top