[1.0/1.1] Linking to a totally separate form from another form.
The way how I traverse through different forms are:
(There are 2 forms, form1 and form2)
This is form1:
form2 f = new form2();
f.Show();
....
And from inside form1 you could link to form2. That is cool. But if form1 disposes form2 also will dispose since it's a childform to the former.
Is there any way I could Open form2 such that if form1 is closed, form2 will still be running?
Jennifer
Re: [1.0/1.1] Linking to a totally separate form from another form.
i ddnt get the question:
wat i do wiv mine is dis:
Code:
this.hide();
form2 f2 = new form2();
f2.show();
then i add a code in the form closing event handler
Code:
foreach (Form var in Application.OpenForms)
{
//close all forms apart from the form the user is at
//to make sure all forms have been closed
if (var != this)
{
var.Dispose();
}
}
//close current form
this.Dispose();
to make sure all bkground process have been disposed wen you close the application
Re: [1.0/1.1] Linking to a totally separate form from another form.
this.hide();
form2 f2 = new form2();
f2.show();
This is exactly what I do. But the main form is not closed, it is simply hidden. I want to start a totally new form independent of its existence. if i had:
form2 f2 = new form2();
f2.show();
without the this.hide(), then I wil have two forms, form1 and form2 with form1 being the mainform. Now if I close form1, form2 wil also close since it is a child process to form1. I want to create a situation when form2 is independent so that if form1 is closed, form2 still remains alive.
Re: [1.0/1.1] Linking to a totally separate form from another form.
That's why you should add the form closing event for each form so that the remaining processes in the background will be closed...
so far that's the only way i have figured on doing this..
Code:
private void frmNames_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Do you want to exit?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
//thank you message
MessageBox.Show("Thank you for using the program", "Goodbye");
//closing all forms in the background process
foreach (Form var in Application.OpenForms)
{
//close all forms apart from the form the user is at
//to make sure all forms have been closed
if (var != this)
{
var.Dispose();
}
}
//close current form
this.Dispose();
}
else
{
// prevent the Form.Closing event from continuing execution
e.Cancel = true;
}
}
this ensures that when you close the newly initialzed form...all background process also gets closed
hope this helps
Re: [1.0/1.1] Linking to a totally separate form from another form.
You could create it where the other form is created (the program.cs). I think that'll work.