Back to Devexpress

RichEditControl.EncryptedFilePasswordCheckFailed Event

wpf-devexpress-dot-xpf-dot-richedit-dot-richeditcontrol-2baff60c.md

latest6.8 KB
Original Source

RichEditControl.EncryptedFilePasswordCheckFailed Event

Occurs when the encryption password is empty or invalid.

Namespace : DevExpress.Xpf.RichEdit

Assembly : DevExpress.Xpf.RichEdit.v25.2.dll

NuGet Package : DevExpress.Wpf.RichEdit

Declaration

csharp
public event EncryptedFilePasswordCheckFailedEventHandler EncryptedFilePasswordCheckFailed
vb
Public Event EncryptedFilePasswordCheckFailed As EncryptedFilePasswordCheckFailedEventHandler

Event Data

The EncryptedFilePasswordCheckFailed event's data class is EncryptedFilePasswordCheckFailedEventArgs. The following properties provide information specific to this event:

PropertyDescription
DocumentNameGets the encrypted document’s name.
ErrorObtains the error type caused the event to raise.
HandledGets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing. Inherited from HandledEventArgs.
TryAgainGets or sets whether to prompt with a password again.

Remarks

Hanlde the EncryptedFilePasswordCheckFailed event to determine the password error (PasswordRequired or RichEditDecryptionError.WrongPassword), and specify whether to enable a new password request (TryAgain).

If the TryAgain property is set to true, the RichEditControl.EncryptedFilePasswordRequested event occurs. The RichEditControl.InvalidFormatException event fires when the TryAgain property is not specifies or set to false.

View Example: Document Encryption (Simple Example)

csharp
int tryCount = 4;

private void RichEditControl1_EncryptedFilePasswordRequested(object sender, EncryptedFilePasswordRequestedEventArgs e)
{
    //Count the amount of attempts to enter the password
    if (tryCount > 0)
    {
        tryCount--;
    }
}

private void RichEditControl1_EncryptedFilePasswordCheckFailed(object sender, EncryptedFilePasswordCheckFailedEventArgs e)
{
    //Analyze the error led to this event
    switch (e.Error)
    {
        case RichEditDecryptionError.PasswordRequired:
            if (tryCount > 0)
            {
                e.TryAgain = true;
                e.Handled = true;
                System.Windows.Forms.MessageBox.Show("You did not enter the password!", String.Format("{0} attempts left", tryCount));
            }
            else
                e.TryAgain = false;

            break;

        case RichEditDecryptionError.WrongPassword:
            if (tryCount > 0)
            {
                if (System.Windows.Forms.MessageBox.Show("The password is incorrect. Try Again?", string.Format("{0} attempts left", tryCount),
                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
                {
                    e.TryAgain = true;
                    e.Handled = true;
                }
            }
            break;
    }

}
vb
Private tryCount As Integer = 4

Private Sub RichEditControl1_EncryptedFilePasswordRequested(ByVal sender As Object, ByVal e As EncryptedFilePasswordRequestedEventArgs)
    'Count the amount of attempts to enter the password
    If tryCount > 0 Then
        tryCount -= 1
    End If
End Sub

Private Sub RichEditControl1_EncryptedFilePasswordCheckFailed(ByVal sender As Object, ByVal e As EncryptedFilePasswordCheckFailedEventArgs)
    'Analyze the error led to this event
    Select Case e.[Error]
        Case RichEditDecryptionError.PasswordRequired

            If tryCount > 0 Then
                e.TryAgain = True
                e.Handled = True
                System.Windows.Forms.MessageBox.Show("You did not enter the password!", String.Format("{0} attempts left", tryCount))
            Else
                e.TryAgain = False
            End If

        Case RichEditDecryptionError.WrongPassword

            If tryCount > 0 Then

                If System.Windows.Forms.MessageBox.Show("The password is incorrect. Try Again?", String.Format("{0} attempts left", tryCount), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = System.Windows.Forms.DialogResult.Yes Then
                    e.TryAgain = True
                    e.Handled = True
                End If
            End If
    End Select
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the EncryptedFilePasswordCheckFailed event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-richedit-document-encryption/CS/DXRichEdit_Encryption/MainWindow.xaml#L42

xml
EncryptedFilePasswordRequested="RichEditControl1_EncryptedFilePasswordRequested"
EncryptedFilePasswordCheckFailed="RichEditControl1_EncryptedFilePasswordCheckFailed"
DecryptionFailed="RichEditControl1_DecryptionFailed">

See Also

RichEditControl Class

RichEditControl Members

DevExpress.Xpf.RichEdit Namespace