What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Call a "parent" method.

Call a "parent" method.
Author: Message:
leito
Senior Member
****

Avatar
Chameleon by KeyStorm

Posts: 720
Reputation: 5
38 / Male / –
Joined: Apr 2003
O.P. Call a "parent" method.
Hey Guys. I did a Thread hours ago, but I can't find it. I search and use latest.php but nothing. Maybe I didn't published it.

I'm using improperly the term "parent" since what I need isn't about inheritance.
I'm programming in C# and I'm trying to call a Form1 Method from inside and object declared and initialized on Form1.

Something likes this.

public partial class Form1 : Form
    {
        MyObject o;

        public Form1()
        {
            this.o = new MyObject();
            //Constructor Body
        }

        public void method()
        {
            //Method Body
        }
    }

class MyObject
    {
        form1.method(); //Not any Form1 but the "parent" Form1 class.
    }

I can't search in Google because I don't know what to search, so please help. Thank you in advance for your help.

Leito

Edit: Now I know, It was deleted. Since I posted in a WRONG forum. :P

This post was edited on 03-07-2006 at 06:03 AM by leito.
[Image: leonelgalan.png]
03-07-2006 05:59 AM
Profile E-Mail PM Find Quote Report
The Brain
Junior Member
**

Avatar

Posts: 49
Reputation: 1
– / Male / Flag
Joined: Jan 2003
RE: Call a "parent" method.
I've never used C#, but this is based on my java knowledge. I can't see it being possible just you've done that. But, if every MyObject object is going to need to call a method in 'its' Form1, why not give your MyObject a reference to its Form1.

code:
public partial class Form1 : Form
    {
        MyObject o;

        public Form1()
        {
            this.o = new MyObject(this);
            //Constructor Body
        }

        public void method()
        {
            //Method Body
        }
    }

class MyObject
    {
        Form1 myform;
        //Constructor, takes Form1 object, assigns to myForm vairable
        myForm.method(); //Not any Form1 but the "parent" Form1 class.
    }


I think that's what you're looking for - let me know if it works for you like you wanted.
03-07-2006 10:30 AM
Profile PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: Call a "parent" method.
The other option is to look at embedded classes. If you want more info, I'll see if I can find where I've used inner classes in Java myself.
[Image: spartaafk.png]
03-07-2006 02:13 PM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On