Are you sure you want to cancel?

Wizard for Windows Forms Forum

Posted 13 years ago by Warren J. Hairston - President, Logical Operators, Inc.
Version: 3.0.0123
Avatar
Is there an easy way to make the Wizard or WizardDialog prompt the user with "Are you sure you want to cancel the wizard?"

I looked at the Wizard's CancelButtonClick event, but there's no way to cancel that event if the user changes his mind.

I also tried capturing the Dialog's FormClosing event (which seemed to work OK for Cancel or dialog closure), but then my warning dialog fires even when the user completes the wizard and clicks the Finish button.

Am I overlooking something? Thanks!

Comments (4)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Warren,

We previously had the same thing with the Finish button and added a new property to control that button's DialogResult but for some reason didn't add the same thing for the Cancel button, which should have been done as well. It's now added for the next maintenance release.

However this related post will tell you how to do a workaround for now until the next release:
http://www.actiprosoftware.com/Support/Forums/ViewForumTopic.aspx?ForumTopicID=1382


Actipro Software Support

Posted 13 years ago by Warren J. Hairston - President, Logical Operators, Inc.
Avatar
Thanks - it looks like the workaround will take care of the issue for me.

I am now processing two events: the Wizard's CancelButtonClick() and the Dialog's FormClosing(). Between the two events, I can now ask "are you sure" if the user closes the form with either the Cancel button or by clicking the close "X" in the corner of the window.

In the CancelButtonClick handler, I display the "are you sure" dialog, then set DialogResult = DialogResult.None if the user chooses to stay in the wizard.

In the Dialog's FormClosing handler, I display the same "are you sure" dialog if the DialogResult is not equal to DialogResult.OK. This allows the "are you sure" dialog to be skipped if this form was closed due to a Finish button click.
Posted 13 years ago by Warren J. Hairston - President, Logical Operators, Inc.
Avatar
I'm finally trying to make use of this new CancelButtonDialogResult feature to prevent the user from closing the wizard, but I'm obviously not understanding how you intended this feature to fix my original problem.

I am providing an event handler for Wizard.CancelButtonClick. I warn the user that his changes will be discarded and ask if he's sure he wants to cancel. If he answers No, I set CancelButtonDialogResult = DialogResult.None, otherwise I set it to DialogResult.Cancel. Either way, the wizard closes, which is obviously NOT what I'm trying to accomplish.

I'm also providing an event handler for the WizardDialog's FormClosing event which should prompt the user if he closes the WizardDialog using the "X" in the upper right corner. It works similarly, the major difference being that the EventArgs passed to WizardDialog.FormClosing has a Cancel property. The big problem here is that if the user clicks the Cancel button and the dialog starts to close, then the FormClosing event handler asks again "Are you sure?"

How do I prevent the wizard from closing when the user clicks the Cancel button, then says "No - I don't really want to cancel"? (It really seems to me that the EventArgs for Wizard.CancelButtonClick needs to have a Cancel property that signals that the wizard should not close.)
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Warren,

If you are doing custom cancel validation code, you should set CancelButtonDialogResult = DialogResult.None and leave it that way. Then in your CancelButtonClick event, you can set the Form.DialogResult property instead. If that doesn't close the Form even when you set it to DialogResult.Cancel then you might also have to call Form.Close in that situation. But if you leave it DialogResult.None then the Form will not close.

I hope that explains it.


Actipro Software Support

The latest build of this product (v2020.1 build 0400) was released 7 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.