error when i try to not exit with program when i press button no in messagebox
-
hi i have a program in c# that when i press button exit it appears a message box that tell you if you want to exit from the program or not. But if you press No the program make exit. private void btnLogout_Click(object sender, EventArgs e) { if (MessageBox.Show("are you sure?you want to exit?;","", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Application.Exit(); } }
-
hi i have a program in c# that when i press button exit it appears a message box that tell you if you want to exit from the program or not. But if you press No the program make exit. private void btnLogout_Click(object sender, EventArgs e) { if (MessageBox.Show("are you sure?you want to exit?;","", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Application.Exit(); } }
Not from that code - if I paste it in and hook up the event then it does what I expect. Shows the box, press Yes and it exits. Press No and it doesn't. Check that you are executing the right code: put a breakpoint on the
if
line, and see if the debugger hits it.The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
-
Not from that code - if I paste it in and hook up the event then it does what I expect. Shows the box, press Yes and it exits. Press No and it doesn't. Check that you are executing the right code: put a breakpoint on the
if
line, and see if the debugger hits it.The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
Sometimes when I have an issue like this, I'll break it out. Store the result of the messagebox in a variable and stop at that point. You can see exactly what is happening each step. What OriginalGriff said is the first step.
-
Sometimes when I have an issue like this, I'll break it out. Store the result of the messagebox in a variable and stop at that point. You can see exactly what is happening each step. What OriginalGriff said is the first step.
I'm pretty sure that OriginalGriff knew this. You replied to OG, and not to the OP - who won't be notified that there's been a reply to a reply.
I was brought up to respect my elders. I don't respect many people nowadays.
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier -
Not from that code - if I paste it in and hook up the event then it does what I expect. Shows the box, press Yes and it exits. Press No and it doesn't. Check that you are executing the right code: put a breakpoint on the
if
line, and see if the debugger hits it.The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
-
Then you need to start by looking at the button you press in the designer, and see where a click event is taking you. Because if the debugger isn't hitting the
if
condition, then it isn't executing that method...:laugh:The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
-
hi i have a program in c# that when i press button exit it appears a message box that tell you if you want to exit from the program or not. But if you press No the program make exit. private void btnLogout_Click(object sender, EventArgs e) { if (MessageBox.Show("are you sure?you want to exit?;","", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Application.Exit(); } }
Is that
btnLogout
also theCancelButton
of your form? -
Is that
btnLogout
also theCancelButton
of your form? -
Then you must handle the Form Closing event, and set its Cancel property to true in case you do not want to close the form (in btnLogout_Click just do a this.Close()).
-
Then you must handle the Form Closing event, and set its Cancel property to true in case you do not want to close the form (in btnLogout_Click just do a this.Close()).
for the use that i want it i just make none the cancel button property that has the logout_click button :) so i use only the command application.exit(); and when i press button logout and in messagebox NO then it stay in the form that i am at the same time