Child form code access to parent code object

G

Guest

Hello,

I'm sorry for such a basic question, but here it is: I'm creating a VS2005
C# forms application. In the parent form I have a button that opens a child
form. In the code for the parent form I have some public objects and some
public methods. How can the child code access those objects and methods? I
know that the child has access to the parent properties by using this.Parent,
but the only members I see in the parent are the very same properties that
are available when laying out the form in the GUI designer (AcceptButton,
AutoScroll, etc.). Are the publics somehow also available using this
mechanism (or how should it be done)?

Thanks
 
M

Marc Gravell

You can cast "Parent" to the actual type, e.g.

MyParentType parent = this.Parent as MyParentType;
if(parent != null) {
// have access to parent.MyFunkyData
}

Alternatively, the parent can hand the resources to the child (via
properties etc) when creating it. If the intention is to update the
parent form's UI, then this can often be better done with events.

Marc
 

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