Shoutbox

Call a "parent" method. - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Call a "parent" method. (/showthread.php?tid=56548)

Call a "parent" method. by leito on 03-07-2006 at 05:59 AM

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


RE: Call a "parent" method. by The Brain on 03-07-2006 at 10:30 AM

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.
RE: Call a "parent" method. by RaceProUK on 03-07-2006 at 02:13 PM

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.