简体   繁体   中英

MainForm access method from another form

I want to transform WinForm to WPF as follow code:

Login form:

public partial class Login : Form
{
    public Login()
    {
        InitializeComponent();
    }
}

public static XmppClientConnection getXmpp()
{
    return xmppCon;
}

MainForm:

public partial class MainForm: Form
{
    XmppClientConnection xmppCon = Login.getXmpp(); // It's okay to access
    public MainForm()
    {
        InitializeComponent();
    }
}

WPF Code:

public partial class MainForm: Form
{
    XmppClientConnection xmppCon = Login.getXmpp(); // my Login can not access getXmpp method;
    public MainForm()
    {
        InitializeComponent();
    }
}

Error with Login.getXmpp at line: XmppClientConnection xmppCon = Login.getXmpp();

My question is, why MainForm can't access method getXmpp from Login form?

You WPF code is the same as your winforms code so I think you've pasted in the wrong info there. It's possible they have a different namespace or are in different projects?

在Login类中未定义方法getXmpp。

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