简体   繁体   中英

Having trouble with C# form passing

I'm currently trying to get into C#, after doing a ton of Java. I wanted to pass my GUI Form to another class, but I run into some trouble trying to access its containers etc. from there.

This is the autogenerated Form class:

namespace Wecker
{
    public partial class WeckerDesign : Form
    {
        public WeckerDesign()
        {
            InitializeComponent();
            new WeckerRun(this);
        }
    }
}

and this is the recieving class:

namespace Wecker
{
    class WeckerRun
    {
        WeckerDesign wdesign = new WeckerDesign();

        public WeckerRun(WeckerDesign wdesign)
        {

            this.wdesign = wdesign;
            new DisplayClock(wdesign);
        }
    }
}

However, when I am trying to access the container "clockfield" from the recieving class, I can't find it. However, in the passing class, I can easily get there with this.clockpanel. ... and so on.

The recieving class won't even suggest me that. In Java, I would simply pass down my class as a whole with "this" in order to have the exact same reference in the other class, which I can treat as if I would do it in the original class where I got that object reference from.

How do I do this in C#?

How is your "clockpanel" field or property defined? It will need to be public to be accessible from outside the class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM