DRaiko,
Because you followed up my post where I suggested a control rather than a
form is more appropriate , because besides the MDI scenarios when one makes
a form child (TopLevel = false) actually the form becomes child window and
in this case control is more appropriate as lightweight control, your
suggestion will work only in a case when control is created at run time.
If one tries to drag and drop control wich has constructor without
parameters and with parameters designer will use the one without. If you
don't privide constructor without paramters VS will report an error when
trying to add the control.
The problem can be solved by creating a designer to that control. which will
initialize a property with the parent of the control. The same as MainMenu
designer does. However in a case of control (not component) where Parent
will be set as soon as the control is added to the control collection one
cas save some work processing ParentChanged event.
Yor suggestion work when
1. It is a form. Form's always are created at run time
2. It is a control and it is created at run time only. Design time for such
a control won't work.
Again, yes you sollution is ok, but you shouls've followed up the original
post. Form's doesn't have parents they have "owners"
--
B\rgds
Stoitcho Goutsev (100) [C# MVP]
[quoted text, click to view] "DRaiko" <draiko@rhenus.de> wrote in message
news:3d60d02c.0407202317.30e29797@posting.google.com...
> Hi Stoitcho,
>
> if you look at the sample in the first mail after
> "Currently I am doing this in the parent form ... " (at the end),
> you will see, that it has nothing to do with the design mode.
> So, your question "whether you want to write you own designers"
> is already answered.
>
>
> Regards,
> Dima.
>
>
> "Stoitcho Goutsev \(100\) [C# MVP]" <100@100.com> wrote in message
news:<essxPM2aEHA.2056@TK2MSFTNGP12.phx.gbl>...
> > Yes, it is possible, but the designer uses by default the constructor
> > without parameters. The question is whether you want ot write you own
> > designers for the components or want to go with the default one.
> >
> > --
> >
> > Stoitcho Goutsev (100) [C# MVP]
> >
> >
> > "DRaiko" <draiko@rhenus.de> wrote in message
> > news:3d60d02c.0407152326.1a08dcca@posting.google.com...
> > > Hi,
> > >
> > > maybe i'm missing the point, but is it not possible to pass a parent
> > > pointer into the ctor?
> > >
> > > ChildForm frm = new ChildForm( this);
> > >
> > > and the ctor makes with it what it wants:
> > > public ChildForm( Form parentForm){
> > > if( parentForm != null){
> > > . . .
> > > }
> > > }
> > >
> > > Well, the ctor is a not-default one. Sometimes this is not good.
> > >
> > > HTH, Dima.
> > >
> > > "Stoitcho Goutsev \(100\) [C# MVP]" <100@100.com> wrote in message
> > news:<#KtplxnaEHA.3664@TK2MSFTNGP12.phx.gbl>...
> > > > Hi Deena,
> > > >
> > > > By child form do you mean control? Anyways, in the constructor is
too
> > early.
> > > > Paren property is not set. It will be set as soon as the control is
> > added to
> > > > the parent control collection.
> > > >
> > > > So you can handle children ParentChanged event and look for the form
> > there.
> > > > You can do that either by hooking the event or overriding
> > OnParentChanged
> > > > method if you provide the class for the child control.
> > > >
> > > > --
> > > > HTH
> > > > Stoitcho Goutsev (100) [C# MVP]
> > > >
> > > >
> > > > "Deena" <dg@dg.com> wrote in message
> > > > news:e48StqnaEHA.3480@TK2MSFTNGP11.phx.gbl...
> > > > > I want to get a reference to the parent form in the constructor of
a
> > child
> > > > > form? I.e. I want to do something like this :
> > > > >
> > > > > FormX Child = new FormX(); //FormX inherits from the Form class
> > > > >
> > > > > In Child's constructor I want find the parent form? I've tried
..Parent
> > and
> > > > > .FindForm() to no avail! Reason for wanting to do this is so that
a
> > parent
> > > > > form can keep a list of all it's child forms. So whenever a child
form
> > is
> > > > > created it can notify it's parent that it exists.
> > > > >
> > > > >
> > > > > public AbstractDialog()
> > > > >
> > > > > {
> > > > >
> > > > > //
> > > > >
> > > > > // Required for Windows Form Designer support
> > > > >
> > > > > //
> > > > >
> > > > > InitializeComponent();
> > > > >
> > > > > // If this is a child window then let it's parent know it was
created
> > > > >
> > > > > AbstractDialog parentForm = (AbstractDialog) this.Parent; //
> > > > > ????????????????????????????????????????????????????????????????
> > > > >
> > > > > if (parentForm != null)
> > > > >
> > > > > {
> > > > >
> > > > > parentForm.AddChildWindow = this;
> > > > >
> > > > > }
> > > > >
> > > > >
> > > > > }
> > > > >
> > > > >
> > > > >
> > > > > where.....
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > // Adds child window to list
> > > > >
> > > > > public System.Windows.Forms.Form AddChildWindow
> > > > >
> > > > > {
> > > > >
> > > > > // Add to list
> > > > >
> > > > > set
> > > > >
> > > > > {
> > > > >
> > > > > formsList.Add(value);
> > > > >
> > > > > }
> >
> > > > > }
> > > > >
> > > > >
> > > > >
> > > > > Currently I am doing this in the parent form:
> > > > >
> > > > > FormX Child = new FormX(); //FormX inherits from the Form class
> > > > > Child.AddChildWindow = this; //Look at above code
> > > > >
> > > > > Which works but it would be cool if I could do it in the
constructor.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >