WizardForm.CancelWizard Method

Definition

When overridden in a derived class, indicates that the user has canceled the wizard form.

protected:
 virtual void CancelWizard();
protected virtual void CancelWizard ();
abstract member CancelWizard : unit -> unit
override this.CancelWizard : unit -> unit
Protected Overridable Sub CancelWizard ()

Examples

The following example demonstrates the CancelWizard method. In this example, the CancelWizard method requires the user to respond to a dialog box to confirm the cancellation. This code example is part of a larger example provided for the WizardForm class.

// Customize the CancelWizard method.
protected override void CancelWizard()
{
    //Check the IsCancellable property before performing a cancel.
    if (IsCancellable)
    {
        // Verify that the user wants to cancel the wizard.
        DialogResult result = ShowMessage("Are you sure you want to exit?",
            MessageBoxButtons.YesNo,
            MessageBoxIcon.Question,
            MessageBoxDefaultButton.Button2);
        if (result == DialogResult.Yes)
        {
            base.StopTaskProgress();
            base.CancelWizard();
        }
    }
}
// Customize the CancelWizard method.
protected override void CancelWizard()
{
    //Check the IsCancellable property before performing a cancel.
    if (IsCancellable)
    {
        // Verify that the user wants to cancel the wizard.
        DialogResult result = ShowMessage("Are you sure you want to exit?",
            MessageBoxButtons.YesNo,
            MessageBoxIcon.Question,
            MessageBoxDefaultButton.Button2);
        if (result == DialogResult.Yes)
        {
            base.StopTaskProgress();
            base.CancelWizard();
        }
    }
}

Remarks

If implemented in your code, this method is called when the user cancels the wizard form by clicking the Cancel button.

Your code should check the value of the IsCancellable property before it closes the wizard form to determine whether the wizard can be canceled.

This method enables you to create a custom CancelWizard method.

Applies to