How to close two form without using Application.Exi t() the FormObj.Close() doesnt work
How to close two form without using Application.Exit() the FormObj.Close() doesnt wok
Collapse
X
-
Tags: None
-
Can you be more specific? Are you trying to shut down your entire program, or just close a form and let another program have control?
That said, closing your main form should allow the application to exit normally. If it's not, you might have something else running and would have to check your code.
This is speculation though, I can't really say much else until you provide more details about your program and what is happening. -
I am trying to close 2 form's using f1.Close() and f2.close() where f1 & f2 are the from1 & form2 objects. But these lines are not working.And I want the application running after closing these 2 from's.So I do not want to use Application.Clo se() method.Comment
-
Calling close on the form should work so if it's not, something else is going on. The question you need to ask yourself is, why?
In both of those forms, do you have any code anywhere (ie, the Form Closing event) that will cancel the close? How/where are you calling the close on those forms?
Calling a dispose might work, but it might be a good idea to understand why your forms aren't closing.Comment
-
You can close forms only if you are closing those forms from the same class in which they are accessible. As an example i declared two forms within Main form and opened both the forms when the main form is loading i.e within the Form_Load event of the main form. and then i closed both the form when user clicked the button present in the main form.
Code:Form f1 = new Form(); Form f2 = new Form(); private void Form1_Load(object sender, EventArgs e) { f1.Show(); f2.Show(); } private void button1_Click(object sender, EventArgs e) { f1.Close(); f2.Close(); }Comment
Comment