PC Review


Reply
Thread Tools Rate Thread

Child form code access to parent code object

 
 
=?Utf-8?B?UmF5IE1pdGNoZWxs?=
Guest
Posts: n/a
 
      1st May 2007
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
 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      1st May 2007
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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run Code in parent form from subform =?Utf-8?B?VHJhY2V5?= Microsoft Access VBA Modules 4 20th Apr 2007 06:20 PM
Code Review! Parent-child relationships Danny Tuppeny Microsoft C# .NET 4 18th Nov 2005 11:13 PM
RE: MDI Parent Toolbar access in Child form =?Utf-8?B?R3JrRW5naW5lZXI=?= Microsoft Dot NET Framework Forms 0 21st Apr 2005 07:16 PM
passing values from child form to an object in parent form. frixx net via .NET 247 Microsoft VB .NET 2 26th Jun 2004 09:06 PM
Capturing the value of a parent form in code TJ Microsoft Access Form Coding 1 5th Jan 2004 08:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:02 AM.