Question

I have a project, where a wizard form is called to make a project. On the end of the wizard I want to send a 'world' object back to a variable in the Main form. But If I give the main form with it through the constructor I can't access it's methods or properties. Am I doing something wrong?

here is my code:

main form

private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
    this.NewProject();
}

private void NewProject()
{
    var myForm = new ProjectWizard(this);
    myForm.Show();
}

Wizard form code:

public ProjectWizard(Form form)
{
    InitializeComponent();
    MainForm = form;
}

private void finishButton_Click(object sender, EventArgs e)
{
    //World world = new World();
    //MainForm.CurrentWorld = world;
}

Thanks in advance.

Was it helpful?

Solution

You just need to make CurrentWorld public or internal on the MainForm class. Honestly, you're doing everything else right!

UPDATE: also make sure that the MainForm private field declared in Form1 is of the type MainForm and not just Form. So, change the constructor a tidge too:

public ProjectWizard(MainForm form)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top