Encrypt Document Dialog

  • 2 minutes to read

The RichEditControl ships with integrated Encrypt Document dialog, shown in the images below.

IMAGE

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.

IMAGE

Invoke the Dialog in Code

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.

customize 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;
    }
}
TIP

Use Document.Encryption option to specify the document encryption options (password and encryption type) in code.