Can not get dialog's ParentForm??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, everyone:

I have a dialog form need to initial some data from its ParentForm, but I can not get its ParentForm. what I have done is:

when I click one button1 on Form1, it does:
{
dialog d=new dialog();
d.ShowDialog();
}

in the Dialog form, after initialize the components, even I check its ParentForm
if(this.ParentForm==null)
{
MessageBox.Show("no parent form");
}

I always get "no parent form".

Could anyone tell me what's wrong I have done?

Sincerely,

Haiwen
 
In the ShowDialog call use the overloaded version that allow you to input a
form. ie d.ShowDialog(me)

That will set the parent.

Lloyd Sheen
haiwen said:
Hello, everyone:

I have a dialog form need to initial some data from its ParentForm, but I
can not get its ParentForm. what I have done is:
 
ParentForm will return the parent of MdiChild forms

Form myChild = new Form();
myChild.MdiParent = this;

Inside myChild Form you can get parent form.

string parentname = myChild.ParentForm.Name

--
Shak
(Houston)


haiwen said:
Hello, everyone:

I have a dialog form need to initial some data from its ParentForm, but I
can not get its ParentForm. what I have done is:
 
Hello, Shakir and Lloyd:

Thank you for your reply.

For MDI form, "myChild.MdiParent = this" does work, but my problem is I can not get the parentForm from the dialog. Even I try follow:

dialog d=new dialog();
d.ShowDialog(this); //it seems this is owner,not parentForm

from the dialog form:

if(this.ParentForm==null )

still true, of course, this.Owner is not equal null.

I just wonder why ParentForm does not work in dialog?

Thanks again.

Sincerely,

Haiwen


this.
 
Back
Top