Thank you. I tried it and it closed but never took it out of memory when the program was completely closed down. I always still had to do the same thing: ctrl alt delete.
This is in both forms becuse VS put it there:
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
I tried removing it but that did not fix the problem either.
Very frustrated!!
Here is what I have got:
//form1:
static void Main()
{
Form3 frm3=new Form3();
frm3.Show();
Application.Run();
}
private void Form1_Closed(object sender, System.EventArgs e)
{
Application.Exit();
}
//form3:
private void YES_Click(object sender, System.EventArgs e)
{
YES.Enabled=false;
Form1 frm1 = new Form1();
frm1.Show();
this.Close();
}
It never clears out of memory!!! Please help!
But the problem is that I do not want the first window to stay in the tray (it is the one with Main() in it. So maybe I can't close it) when I show and run the second window.
I know what might fix it!!!!
I will just put Main in the other form!!!!!!!!
I'll post back.
When I use this.Close(); it does the same thing as closing the whole application.
private void YES_Click(object sender, System.EventArgs e)
{
YES.Enabled=false;
Form1 frm1 = new Form1();
frm1.Show();
this.Close();
}
I also tried creating a Form3 object in Form1 but the frm3.Close(); did nothing at all.
I think the forms are connected too tightly somehow because when I close Form3 where main is I close both. ShowDialog(); works but it does not close the Form3 until Form1 is closed.
Is there any way around that, so that I can immediately close Form3?
You forgot the () I think, and with them it works.
Also, It ends as soon as it opens when I have
Application.Exit();
there. How can I close the Form3 only?
And, what is the difference between Show and ShowDialog?
Running a a form from a form
I have 2 classes:
public class Form1 : System.Windows.Forms.Form
public class Form3 : System.Windows.Forms.Form
--------------------------------------------
Main() starts Form3 (simple yes, no label):
static void Main()
{
Application.Run(new Form3());
}
--------------------------------------------
For the YES button I have the other form I want to run and close the Form3.
private void YES_Click(object sender, System.EventArgs e)
{
Application.Run(new Form1);
Application.Exit();
}
--------------------------------------------
When I run this and press YES an error box pops up that says:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.windows.forms.dll
Additional information: It is invalid to start a second message loop on a single thread. Use Application.RunDialog or Form.ShowDialog instead.
--------------------------------------------
When I try to use Form.ShowDialog it won't compile and says it needs an object.
When I try to use Application.RunDialog it says it is unaccessable due to its protection level.
What should I do?