Hey
After some time, I'm started again into the language C#. I have a windows form application with three different forms and I have functions that are interacting with more then one form. An easy example is the close-Button. It should not only close the currently active form but also the main form which is invisible in the background. Also the "Back to MAin Form" button has the same problem, because I don't know how the instance of the main form is called. How can I find out how the instance is named?
Loading

Dorababu MekaRank #457 · 5.5K reputationPosted Aug 14, 2012, 4:42 AM EDT
Simon5 reputationPosted Aug 14, 2012, 4:45 AM EDT
In the case of the "Back to Main Form"-button I want to close the active form and make the main form visible again.
Dorababu MekaRank #457 · 5.5K reputationPosted Aug 14, 2012, 4:51 AM EDT
Form2 frm =new Form2(); // give your form name
frm.hide(); or this.Hide();
Simon5 reputationPosted Aug 14, 2012, 5:05 AM EDT
I have a form "frmNewTest" with two buttons:
private void btnClose_Click(object sender, EventArgs e)
{
this.close(); //for closing the frmNewTest
//and then I want to close the frmStart too, which is open in the background but hidden. But what is it object name to call the close-method?
}
private void btnMainMenu_Click(object sender, EventArgs e)
{
this.close();
[objectname of the startform].show();
}
again, the same problem.
Dorababu MekaRank #457 · 5.5K reputationPosted Aug 14, 2012, 5:12 AM EDT
for (int i = Application.OpenForms.Count - 1; i >= 0; i--)
{
if (Application.OpenForms[i].Name != "Yourmainfromname")
Application.OpenForms[i].Close();
}
Dorababu MekaRank #457 · 5.5K reputationPosted Aug 22, 2012, 12:00 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 22, 2012, 12:52 AM EDT