I am a newbie in C# programming. I am working on a simple Windows form in VS.NET 2005, where there is a label displaying "Welcome to DialogResult Testing form". I have a Exit Button. I want that as soon as the user clicks on the Button in the form, the code in
the Button1_Click Event should get executed which will display a confirmation MessageBox. The code I have entered for the Click Event is something like this:
private void button1_Click(object sender, EventArgs e)
MessageBox.Show("Are you Sure to Exit. Click Yes to Confirm and No to continue", "WinForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (MessageBox.Show"Are you Sure to Exit. Click Yes to Confirm and No to continue", "WinForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes)
MessageBox.Show("Thanx for not terminating me!", "As you wish",MessageBoxButtons.OK, MessageBoxIcon.Information);
Everything went fine, but suddenly a Major problem aroused! On clicking the Exit Button in the form, I get a Confirmation MessageBox displaying, "Are you Sure to Exit. Click Yes to Confirm and No to continue". Below there are two buttons, Yes and No, as per as my coding. But then, when I click on Yes Button to exit the Application, the MessageBox pops up again asking for the same confirmation. Again I click on Yes Button on the MessageBox and then, finally the application gets terminated. The same is in the case of the No button on the MessageBox. I click on No to continue but then the same MessageBox asking for confirmation pops up again. I again click on No and then get the Message "Thanx for not terminating me".
The problem here is that, when I run the application and click on Exit Button, a MessageBox is displayed asking for confirmation. But, if I click on Yes to exit the application, the same confirmation MessageBox is displayed again. And then when I click on Yes Button again, does exits the application. The same is with the No button.
Why does the MessageBox Pops up twice, instead I programmed it for just executing the code after recieving the input from the user, only once. Please help me out. Its very important. If possible, write me the correct code for this. Sorry if I wrote too long.
A friend in need :( is a friend indeed :)
0 · ·