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 ObjectFor开发者_如何学Cm();
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
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.
精彩评论