Click here to Skip to main content
15,878,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is probably a stupid question. It should be an easy thing to do and I thought I had it working but it is not and I have looked, and looked for an answer and been unable to find it.

The problem is I have a form that has an ok button and a cancel button. Under certain circumstances when one of the buttons is clicked I want to show a Messagebox to confirm the action. However, no matter what I do the form is closed. I thought this might work:
C#
if ( DialogResult.Yes == MessageBox.show("Are you sure?","confirm",MessageBoxButtons.YesNo, MessageBoxIcon.Question)
{
    this.close();
else
    return;

However, whether I use this.close() or this.show() or return or not the end result is that the form is closed rather than left showing with the user given a chance to change their selection.

Thanks for the help, sorry to ask such a silly question.

Henry
Posted
Updated 19-Oct-13 20:42pm
v3

That doesn't work. I see I forgot to say that I am using c# with Visual Studio express 2010.

e does not have a cancel property.

Henry
 
Share this answer
 
C#
if ( DialogResult.Yes == MessageBox.show("Are you sure?","confirm",MessageBoxButtons.YesNo, MessageBoxIcon.Question)
{
 e.Cancel=True;
}
else
{
 e.Cancel=False;
return;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900