Back to Devexpress

How to: Utilize a Print Preview Dialog to Adjust Margins in the RichEditControl Document

wpf-118316-controls-and-libraries-rich-text-editor-examples-printing-how-to-utilize-a-print-preview-dialog-to-adjust-margins-in-the-rich-edit-control-document.md

latest2.5 KB
Original Source

How to: Utilize a Print Preview Dialog to Adjust Margins in the RichEditControl Document

  • Nov 29, 2023

This example illustrates how to handle the PrintingSystemBase.AfterMarginsChange event to apply margin settings adjusted in the Print Preview dialog to the document loaded in the RichEditControl. The document is printed via the PrintableComponentLink and the PrintTool.ShowPreviewDialog method is used to display the Print Preview window.

csharp
void PrintingSystem_AfterMarginsChange(object sender, MarginsChangeEventArgs e) {
    // Change document margins in the source RichEditControl
    SectionMargins margins = this.richEditControl1.Document.Sections[0].Margins;
    switch (e.Side) {
        case MarginSide.Left:
            margins.Left = Units.HundredthsOfInchToDocuments((int)e.Value);
            break;
        case MarginSide.Right:
            margins.Right = Units.HundredthsOfInchToDocuments((int)e.Value);
            break;
        case MarginSide.Top:
            margins.Top = Units.HundredthsOfInchToDocuments((int)e.Value);
            break;
        case MarginSide.Bottom:
            margins.Bottom = Units.HundredthsOfInchToDocuments((int)e.Value);
            break;
        default:
            break;
    }

    link.CreateDocument();
}
vb
Private Sub PrintingSystem_AfterMarginsChange(ByVal sender As Object, ByVal e As MarginsChangeEventArgs)
    ' Change document margins in the source RichEditControl
    Dim margins As SectionMargins = Me.richEditControl1.Document.Sections(0).Margins
    Select Case e.Side
        Case MarginSide.Left
            margins.Left = Units.HundredthsOfInchToDocuments(CInt((e.Value)))
        Case MarginSide.Right
            margins.Right = Units.HundredthsOfInchToDocuments(CInt((e.Value)))
        Case MarginSide.Top
            margins.Top = Units.HundredthsOfInchToDocuments(CInt((e.Value)))
        Case MarginSide.Bottom
            margins.Bottom = Units.HundredthsOfInchToDocuments(CInt((e.Value)))
        Case Else
    End Select

    link.CreateDocument()
End Sub