Re: Component constructor in .NET 2.0

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Edward Diener wrote:
Carl Daniel [VC++ MVP] wrote:
Edward Diener wrote:
I looked in the documentation for System.ComponentModel.Component's
constructor but I only noticed a constructor taking no parameters.
My understanding is that there is a second constructor which takes a
System.ComponentModel.IContainer interface object. Has this been the
case in previous .NET releases and has this changed with .NET 2.0 ?

Ildasm shows only the no-args constructor for V1.1 and V2.0. Why do
you believe there's another constructor?

If I use VS2005 to generate a component class, it creates both a no
argument constructor and a constructor which takes a
System.ComponentModel.IContainer container interface with the comment

"///
/// Required for Windows.Forms Class Composition Designer support
///"

This leads me to believe that all component derived classes need to
specify this second constructor. As a component developer I have added
this second constructor to all my components, with the appropriate
logic of adding the component to the container passed in the
constructor. Is this necessary ? What is the story with this second
constructor ? I could find no documentation regarding it in the
VS2005 doc for any .NET component classes.

IIUC, it has no function outside the windows forms designer - effectively an
internal implementation detail of the designer that leaks into your code.

-cd


.



Relevant Pages

  • Re: Deriving - .NET example
    ... represents a windows form. ... Form class has fairly large interface which can be used to manipulate ... When designing custom form via MS Visual Studio designer, ... was a method of the class Form, called from its empty constructor (i.e. ...
    (comp.object)
  • Re: Component constructor in .NET 2.0
    ... constructor but I only noticed a constructor taking no parameters. ... specify this second constructor. ... VS2005 doc for any .NET component classes. ... Still I think it should be documented in the .NET API so that component developers will understand that it is being used by components distributed by Microsoft and that they should use the same technique in order to work well with the windows form designer. ...
    (microsoft.public.dotnet.framework)
  • Re: Want to take the path of specific overloaded constructors from derived class up to just one belo
    ... what that means is the second constructor will first invoke the zero-argument constructor for the class and then execute it's own code. ... public Class B with the Token signature. ... Right now the execution path moves correctly into the lowermost class with the ctor that contains the Token method signature. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Component constructor in .NET 2.0
    ... constructor but I only noticed a constructor taking no parameters. ... If I use VS2005 to generate a component class, it creates both a no argument constructor and a constructor which takes a System.ComponentModel.IContainer container interface with the comment ... This leads me to believe that all component derived classes need to specify this second constructor. ...
    (microsoft.public.dotnet.framework)
  • Re: Constructor initializers
    ... > DerivedClass(int a, int b): ... > class constructor, however I also want the second constructor to execute ...
    (microsoft.public.dotnet.languages.csharp)