Set visibility on parent form from child.

G

Guest

Hi

I'm having trouble setting the main form visible from within the child form. I have set the main form to hide (SignatureMain.Hide())

I then load the child form from within a button on form1

Treatment.ShowDialog()

On the child form Treatment i try to do the following in an Exit button

this.ParentForm.Visible = true
this.Close()

What i'm gettign is the following

An unhandled exception of type 'System.NullReferenceException' occurred in Signature.ex

Additional information: Object reference not set to an instance of an object

NOTE

I have even set the parent form as follows

Treatment.ShowDialog(this)

This is suppose to set the this (SignatureMain) as the parent to Treatment

When i run the debbugger and look at ParentForm, its null??

Thanks
 
G

Guest

Ok i have figured out the solution. Here it is for anyone looking for the information later

When loading a form using: myForm.ShowDialog(this) were "this" is the OWNER of the form you are loading, you need to use in the child form the following to get to its properties

this.Owner.Visible = true; <-- "this" is the child form and i'm accessing the visible property of the parent form (owner)

I'm still not clear as to why Parent and or ParentForm did nto work so if anyone has the answer to that one please post

Enjoy!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top