|
-
Jun 7th, 2006, 08:25 AM
#1
Thread Starter
Hyperactive Member
[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
-
Jun 7th, 2006, 09:19 AM
#2
Hyperactive Member
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
-
Jun 7th, 2006, 09:26 AM
#3
Thread Starter
Hyperactive Member
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.
-
Jun 7th, 2006, 09:32 AM
#4
Hyperactive Member
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
-
Jun 7th, 2006, 12:02 PM
#5
Not NoteMe
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.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|