windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-9d1705a3.md
Occurs when the encryption password is empty or invalid.
Namespace : DevExpress.XtraRichEdit
Assembly : DevExpress.XtraRichEdit.v25.2.dll
NuGet Package : DevExpress.Win.RichEdit
public event EncryptedFilePasswordCheckFailedEventHandler EncryptedFilePasswordCheckFailed
Public Event EncryptedFilePasswordCheckFailed As EncryptedFilePasswordCheckFailedEventHandler
The EncryptedFilePasswordCheckFailed event's data class is EncryptedFilePasswordCheckFailedEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| DocumentName | Gets the encrypted document’s name. |
| Error | Obtains the error type caused the event to raise. |
| Handled | Gets 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. |
| TryAgain | Gets or sets whether to prompt with a password again. |
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)
private void RichEditControl1_EncryptedFilePasswordRequested(object sender, EncryptedFilePasswordRequestedEventArgs e)
{
//Count the number of attempts to enter the password
if (tryCount > 0)
{
tryCount--;
}
}
private void RichEditControl1_EncryptedFilePasswordCheckFailed(object sender, EncryptedFilePasswordCheckFailedEventArgs e)
{
//Analyze the error that led to this event
//Depending on the user input and number of attempts,
//Prompt user to enter a password again
//or create an empty file
switch (e.Error)
{
case RichEditDecryptionError.PasswordRequired:
if (tryCount > 0)
{
e.TryAgain = true;
e.Handled = true;
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 ((MessageBox.Show("The password is incorrect. Try Again?", String.Format(" {0} attempts left", tryCount),
MessageBoxButtons.YesNo)) == DialogResult.Yes)
{
e.TryAgain = true;
e.Handled = true;
}
}
break;
}
}
Private Sub RichEditControl1_EncryptedFilePasswordRequested(ByVal sender As Object, ByVal e As EncryptedFilePasswordRequestedEventArgs) Handles richEditControl1.EncryptedFilePasswordRequested
'Count the number 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) Handles richEditControl1.EncryptedFilePasswordCheckFailed
'Analyze the error that led to this event
'Depending on the user input and number of attempts,
'Prompt user to enter a password again
'or create an empty file
Select Case e.Error
Case RichEditDecryptionError.PasswordRequired
If tryCount > 0 Then
e.TryAgain = True
e.Handled = True
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 (MessageBox.Show("The password is incorrect. Try Again?", String.Format(" {0} attempts left", tryCount), MessageBoxButtons.YesNo)) = DialogResult.Yes Then
e.TryAgain = True
e.Handled = True
End If
End If
End Select
End Sub
See Also