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
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.
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();
}
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