views:

24

answers:

1

Hello All, I'm working on an application and I've encountered a strange issue, that I think should be simple, but isn't. What I'm trying to accomplish is set the main form's title caption to a specific value when the another form closes. Below is my most recent attempt at this.

// From the main form I have
ObjectForm Objects = new ObjectForm();
Objects.GameName = this.Text; // this is a public string on the ObjectForm side

// Here is what I have on the ObjectForm
private void btnOK_click(object sender, EventArgs e)
{
    MainForm Main = new MainForm();
    Main.Text = this.txtGameName.Text;
    this.Close();
}

Any help will be gladly accepted, thanks :D

+1  A: 

You can't just instantiate a new MainForm, you need to get a reference to the existing instance.

Have a look in the documentation at Application.OpenForms

This code you have in your button click handler

MainForm Main = new MainForm(); 
Main.Text = this.txtGameName.Text; 

Instantiates a new MainForm and sets it's title, this is completely separate instance to the MainForm that houses your application.

Gary
MainForm is the primary form and ObjectForm is another form opened up from a toolbar item.
Fo0