Back to Devexpress

Encrypt Document Dialog in rich Text Editor

windowsforms-400749-controls-and-libraries-rich-text-editor-visual-elements-dialogs-encrypt-document-dialog.md

latest3.3 KB
Original Source

Encrypt Document Dialog in rich Text Editor

  • Jun 29, 2021
  • 2 minutes to read

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.

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.

csharp
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;
    }
}
vb
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.