Closing multiple forms C#
I'm currently working with C# windows forms.
I got like 40 cs files, and when the applications works like :
Pressing a button -> Opens new form upon the first one and pressing another button opens another form upon the one before.
Now, whenever I click multiple forms none of the others are closing itself when I'm pressing different buttons, they all stay on the background.
Now, if I use this.Close(); its working with 1, but i got like 40 cs files and it's hard to compile them all..
looking for any suggestion ?
Thank you guys for any sort of help !
public partial class Costumers_Orders : Form
{
public Costumers_Orders()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
NewCostumer mm = new NewCostumer();
mm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Remove_Customer mm = new Remove_Customer();
mm.Show();
}
private void Costumers_Orders_Load(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
Show_Edit_Customer mm = new Show_Edit_Customer();
mm.Show();
}
private void button4_Click(object sender, EventArgs e)
{
Orders_report mm = new Orders_report();
mm.Show();
}
}
c# winforms dialog
New contributor
Angel Adir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I'm currently working with C# windows forms.
I got like 40 cs files, and when the applications works like :
Pressing a button -> Opens new form upon the first one and pressing another button opens another form upon the one before.
Now, whenever I click multiple forms none of the others are closing itself when I'm pressing different buttons, they all stay on the background.
Now, if I use this.Close(); its working with 1, but i got like 40 cs files and it's hard to compile them all..
looking for any suggestion ?
Thank you guys for any sort of help !
public partial class Costumers_Orders : Form
{
public Costumers_Orders()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
NewCostumer mm = new NewCostumer();
mm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Remove_Customer mm = new Remove_Customer();
mm.Show();
}
private void Costumers_Orders_Load(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
Show_Edit_Customer mm = new Show_Edit_Customer();
mm.Show();
}
private void button4_Click(object sender, EventArgs e)
{
Orders_report mm = new Orders_report();
mm.Show();
}
}
c# winforms dialog
New contributor
Angel Adir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Please post your code so we can help you.
– preciousbetine
Dec 27 '18 at 10:57
done, thanks !!
– Angel Adir
Dec 27 '18 at 11:07
check out this; docs.microsoft.com/en-us/dotnet/api/…
– Ufuk Aydın
Dec 27 '18 at 11:11
"Now, if I use this.Close(); its working with 1, but i got like 40 cs files and it's hard to compile them all.." - it is unclear to be what you are asking here. It seems you have a working solution for one form and you are unwilling to implement it for all 40 forms.
– ja72
Dec 27 '18 at 14:58
add a comment |
I'm currently working with C# windows forms.
I got like 40 cs files, and when the applications works like :
Pressing a button -> Opens new form upon the first one and pressing another button opens another form upon the one before.
Now, whenever I click multiple forms none of the others are closing itself when I'm pressing different buttons, they all stay on the background.
Now, if I use this.Close(); its working with 1, but i got like 40 cs files and it's hard to compile them all..
looking for any suggestion ?
Thank you guys for any sort of help !
public partial class Costumers_Orders : Form
{
public Costumers_Orders()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
NewCostumer mm = new NewCostumer();
mm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Remove_Customer mm = new Remove_Customer();
mm.Show();
}
private void Costumers_Orders_Load(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
Show_Edit_Customer mm = new Show_Edit_Customer();
mm.Show();
}
private void button4_Click(object sender, EventArgs e)
{
Orders_report mm = new Orders_report();
mm.Show();
}
}
c# winforms dialog
New contributor
Angel Adir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I'm currently working with C# windows forms.
I got like 40 cs files, and when the applications works like :
Pressing a button -> Opens new form upon the first one and pressing another button opens another form upon the one before.
Now, whenever I click multiple forms none of the others are closing itself when I'm pressing different buttons, they all stay on the background.
Now, if I use this.Close(); its working with 1, but i got like 40 cs files and it's hard to compile them all..
looking for any suggestion ?
Thank you guys for any sort of help !
public partial class Costumers_Orders : Form
{
public Costumers_Orders()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
NewCostumer mm = new NewCostumer();
mm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Remove_Customer mm = new Remove_Customer();
mm.Show();
}
private void Costumers_Orders_Load(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
Show_Edit_Customer mm = new Show_Edit_Customer();
mm.Show();
}
private void button4_Click(object sender, EventArgs e)
{
Orders_report mm = new Orders_report();
mm.Show();
}
}
c# winforms dialog
c# winforms dialog
New contributor
Angel Adir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Angel Adir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Dec 27 '18 at 14:55
ja72
18k347103
18k347103
New contributor
Angel Adir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Dec 27 '18 at 10:54
Angel Adir
12
12
New contributor
Angel Adir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Angel Adir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Angel Adir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Please post your code so we can help you.
– preciousbetine
Dec 27 '18 at 10:57
done, thanks !!
– Angel Adir
Dec 27 '18 at 11:07
check out this; docs.microsoft.com/en-us/dotnet/api/…
– Ufuk Aydın
Dec 27 '18 at 11:11
"Now, if I use this.Close(); its working with 1, but i got like 40 cs files and it's hard to compile them all.." - it is unclear to be what you are asking here. It seems you have a working solution for one form and you are unwilling to implement it for all 40 forms.
– ja72
Dec 27 '18 at 14:58
add a comment |
Please post your code so we can help you.
– preciousbetine
Dec 27 '18 at 10:57
done, thanks !!
– Angel Adir
Dec 27 '18 at 11:07
check out this; docs.microsoft.com/en-us/dotnet/api/…
– Ufuk Aydın
Dec 27 '18 at 11:11
"Now, if I use this.Close(); its working with 1, but i got like 40 cs files and it's hard to compile them all.." - it is unclear to be what you are asking here. It seems you have a working solution for one form and you are unwilling to implement it for all 40 forms.
– ja72
Dec 27 '18 at 14:58
Please post your code so we can help you.
– preciousbetine
Dec 27 '18 at 10:57
Please post your code so we can help you.
– preciousbetine
Dec 27 '18 at 10:57
done, thanks !!
– Angel Adir
Dec 27 '18 at 11:07
done, thanks !!
– Angel Adir
Dec 27 '18 at 11:07
check out this; docs.microsoft.com/en-us/dotnet/api/…
– Ufuk Aydın
Dec 27 '18 at 11:11
check out this; docs.microsoft.com/en-us/dotnet/api/…
– Ufuk Aydın
Dec 27 '18 at 11:11
"Now, if I use this.Close(); its working with 1, but i got like 40 cs files and it's hard to compile them all.." - it is unclear to be what you are asking here. It seems you have a working solution for one form and you are unwilling to implement it for all 40 forms.
– ja72
Dec 27 '18 at 14:58
"Now, if I use this.Close(); its working with 1, but i got like 40 cs files and it's hard to compile them all.." - it is unclear to be what you are asking here. It seems you have a working solution for one form and you are unwilling to implement it for all 40 forms.
– ja72
Dec 27 '18 at 14:58
add a comment |
1 Answer
1
active
oldest
votes
Assuming you only ever want one form open at a time, and that "Costumers" is the main form and can't be closed:
private void button1_Click(object sender, EventArgs e)
{
ShowForm(new NewCostumer());
}
private void ShowForm(Form newForm)
{
List<Form> forms = new List<Form>();
foreach (Form frm in Application.OpenForms)
{
if (!(frm is Costumers))
{
forms.Add(frm);
}
}
foreach (Form frm in forms)
{
frm.Close();
}
newForm.Show();
}
There are other ways you could do this as well.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Angel Adir is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53943862%2fclosing-multiple-forms-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Assuming you only ever want one form open at a time, and that "Costumers" is the main form and can't be closed:
private void button1_Click(object sender, EventArgs e)
{
ShowForm(new NewCostumer());
}
private void ShowForm(Form newForm)
{
List<Form> forms = new List<Form>();
foreach (Form frm in Application.OpenForms)
{
if (!(frm is Costumers))
{
forms.Add(frm);
}
}
foreach (Form frm in forms)
{
frm.Close();
}
newForm.Show();
}
There are other ways you could do this as well.
add a comment |
Assuming you only ever want one form open at a time, and that "Costumers" is the main form and can't be closed:
private void button1_Click(object sender, EventArgs e)
{
ShowForm(new NewCostumer());
}
private void ShowForm(Form newForm)
{
List<Form> forms = new List<Form>();
foreach (Form frm in Application.OpenForms)
{
if (!(frm is Costumers))
{
forms.Add(frm);
}
}
foreach (Form frm in forms)
{
frm.Close();
}
newForm.Show();
}
There are other ways you could do this as well.
add a comment |
Assuming you only ever want one form open at a time, and that "Costumers" is the main form and can't be closed:
private void button1_Click(object sender, EventArgs e)
{
ShowForm(new NewCostumer());
}
private void ShowForm(Form newForm)
{
List<Form> forms = new List<Form>();
foreach (Form frm in Application.OpenForms)
{
if (!(frm is Costumers))
{
forms.Add(frm);
}
}
foreach (Form frm in forms)
{
frm.Close();
}
newForm.Show();
}
There are other ways you could do this as well.
Assuming you only ever want one form open at a time, and that "Costumers" is the main form and can't be closed:
private void button1_Click(object sender, EventArgs e)
{
ShowForm(new NewCostumer());
}
private void ShowForm(Form newForm)
{
List<Form> forms = new List<Form>();
foreach (Form frm in Application.OpenForms)
{
if (!(frm is Costumers))
{
forms.Add(frm);
}
}
foreach (Form frm in forms)
{
frm.Close();
}
newForm.Show();
}
There are other ways you could do this as well.
answered Dec 27 '18 at 14:51
Idle_Mind
22.4k21424
22.4k21424
add a comment |
add a comment |
Angel Adir is a new contributor. Be nice, and check out our Code of Conduct.
Angel Adir is a new contributor. Be nice, and check out our Code of Conduct.
Angel Adir is a new contributor. Be nice, and check out our Code of Conduct.
Angel Adir is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53943862%2fclosing-multiple-forms-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please post your code so we can help you.
– preciousbetine
Dec 27 '18 at 10:57
done, thanks !!
– Angel Adir
Dec 27 '18 at 11:07
check out this; docs.microsoft.com/en-us/dotnet/api/…
– Ufuk Aydın
Dec 27 '18 at 11:11
"Now, if I use this.Close(); its working with 1, but i got like 40 cs files and it's hard to compile them all.." - it is unclear to be what you are asking here. It seems you have a working solution for one form and you are unwilling to implement it for all 40 forms.
– ja72
Dec 27 '18 at 14:58