windowsforms-400749-controls-and-libraries-rich-text-editor-visual-elements-dialogs-encrypt-document-dialog.md
The RichEditControl ships with integrated Encrypt Document dialog, shown in the images below.
End users can click Encrypt with Password on the Home ribbon tab to invoke this dialog. Refer to the How to: Create the RichEditControl with a Ribbon UI topic for details on how to provide the ribbon UI for the RichEditControl.
You can use EncryptDocumentCommand to invoke this dialog. You can handle the DocumentEncryptionQueryNewPasswordFormShowing event to perform actions before an encryption form is displayed, customize the default dialog (modify captions, set default dialog values, implement custom validation, etc.) or substitute it with a new dialog.
The code sample below shows how to handle the EncryptDocumentFormShowing event to change the caption of the Encrypt Document dialog.
using DevExpress.XtraRichEdit.Forms;
class MyEncryptForm : EncryptDocumentForm
{
public MyEncryptForm(IRichEditControl control, EncryptionInfo encryptionInfo) : base(control, encryptionInfo)
{
this.Text = "Password-Protect this Document";
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.richEditControl1.EncryptDocumentFormShowing += RichEditControl1_EncryptDocumentFormShowing;
}
private void RichEditControl1_EncryptDocumentFormShowing(object sender, EncryptDocumentFormShowingEventArgs e)
{
MyEncryptForm frm = new MyEncryptForm(this.richEditControl1, e.EncryptionInfo);
e.DialogResult = frm.ShowDialog();
frm.Dispose();
e.Handled = true;
}
}
Imports DevExpress.XtraRichEdit.Forms
Class MyEncryptForm
Inherits EncryptDocumentForm
Public Sub New(ByVal control As IRichEditControl, ByVal encryptionInfo As EncryptionInfo)
MyBase.New(control, encryptionInfo)
Me.Text = "Password-Protect this Document"
End Sub
End Class
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
Me.richEditControl1.EncryptDocumentFormShowing += AddressOf RichEditControl1_EncryptDocumentFormShowing
End Sub
Private Sub RichEditControl1_EncryptDocumentFormShowing(ByVal sender As Object, ByVal e As EncryptDocumentFormShowingEventArgs)
Dim frm As MyEncryptForm = New MyEncryptForm(Me.richEditControl1, e.EncryptionInfo)
e.DialogResult = frm.ShowDialog()
frm.Dispose()
e.Handled = True
End Sub
End Class
Tip
Use Document.Encryption option to specify the document encryption options (password and encryption type) in code.