I have three forms. All forms are shown and I have a button on the third form. The button should close all the forms including the form where the button was created. Application.Exit() is not suitable for this because I don't want the application to exit including the forms that were not mentioned.
AngelicOne
4
Posting Whiz
Recommended Answers
Jump to PostCall the forms Close() methods of both forms.
If you no longer need the forms you cold call the Dispose() methods.
Jump to PostJust to add to ddanbe`s post:
But you need to have both instances avaliable and forms in state "Open", otherwise will be an error.You can set both Forms asd global and check if they are null whihle trying to close them:
//in form1: Form2 f2; …
Jump to Postif You want close two form and show the first one
try with thisprivate void button1_Click(object sender, EventArgs e) Form1 frm1 = new Form1(); Form2 frm2 = new Form2(); Form3 frm3 = new Form3(); frm2.close(); frm3.close(); frm1.show();
YousafC#
Jump to PostLol, what is this code? You open and close all at once. Strange. There is no point in your code.
Jump to PostHello Sir Mitja I know You are the best developer and i am just new one but this code will close form2 and form3 and show Main Form.if i wrong please Amelioration.I am just new student.
All 22 Replies
ddanbe
2,724
Professional Procrastinator
Featured Poster
Mitja Bonca
557
Nearly a Posting Maven
yousafc#
0
Junior Poster in Training
Mitja Bonca
557
Nearly a Posting Maven
yousafc#
0
Junior Poster in Training
Mitja Bonca
557
Nearly a Posting Maven
yousafc#
0
Junior Poster in Training
Mitja Bonca
557
Nearly a Posting Maven
AngelicOne
4
Posting Whiz
Mitja Bonca
557
Nearly a Posting Maven
AngelicOne
4
Posting Whiz
AngelicOne
4
Posting Whiz
Mitja Bonca
557
Nearly a Posting Maven
AngelicOne
4
Posting Whiz
Mitja Bonca
557
Nearly a Posting Maven
Mitja Bonca
557
Nearly a Posting Maven
AngelicOne
4
Posting Whiz
Mitja Bonca
557
Nearly a Posting Maven
AngelicOne
4
Posting Whiz
Mitja Bonca
557
Nearly a Posting Maven
Mitja Bonca
557
Nearly a Posting Maven
AngelicOne
4
Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.