Back to Devexpress

SectionPageBorders Interface

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-3f9980b5.md

latest6.3 KB
Original Source

SectionPageBorders Interface

Provides access to page border settings in a Section.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
[ComVisible(true)]
public interface SectionPageBorders
vb
<ComVisible(True)>
Public Interface SectionPageBorders

The following members return SectionPageBorders objects:

Remarks

This class introduces the SectionPageBorders.TopBorder, SectionPageBorders.BottomBorder, SectionPageBorders.RightBorder and SectionPageBorders.LeftBorder properties, which specify section page borders.

Example

The following code snippet adds page borders to two sections:

  • In the first section, page borders are shown only on the first page.

  • In the second section, page borders are shown on all pages.

  • C#

  • VB.NET

csharp
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System.Diagnostics;
using System.Drawing;

string fileName = "Test.docx";
using (var wordProcessor = new RichEditDocumentServer()) {
    Document document = wordProcessor.Document;
    // Generate a document with two sections and multiple pages in each section.
    document.AppendText("\f\f\f");
    document.Paragraphs.Append();
    document.AppendSection();
    document.AppendText("\f\f");

    Section firstSection = document.Sections[0];
    SectionPageBorders pageBorders1 = firstSection.PageBorders;

    // Set page borders for the first page of the first section.
    SetPageBorders(pageBorders1.LeftBorder, BorderLineStyle.Single, 1f, Color.Red);
    SetPageBorders(pageBorders1.TopBorder, BorderLineStyle.Single, 1f, Color.Red);
    SetPageBorders(pageBorders1.RightBorder, BorderLineStyle.Single, 1f, Color.Red);
    SetPageBorders(pageBorders1.BottomBorder, BorderLineStyle.Single, 1f, Color.Red);
    pageBorders1.AppliesTo = PageBorderAppliesTo.FirstPage;

    Section secondSection = document.Sections[1];
    SectionPageBorders pageBorders2 = secondSection.PageBorders;

    // Set page borders for all pages of the second section.
    SetPageBorders(pageBorders2.LeftBorder, BorderLineStyle.Double, 1.5f, Color.Green);
    SetPageBorders(pageBorders2.TopBorder, BorderLineStyle.Double, 1.5f, Color.Green);
    SetPageBorders(pageBorders2.RightBorder, BorderLineStyle.Double, 1.5f, Color.Green);
    SetPageBorders(pageBorders2.BottomBorder, BorderLineStyle.Double, 1.5f, Color.Green);
    pageBorders2.AppliesTo = PageBorderAppliesTo.AllPages;
    pageBorders2.ZOrder = PageBorderZOrder.Back;

    wordProcessor.SaveDocument(fileName, DocumentFormat.Docx);
}
void SetPageBorders(PageBorder border, BorderLineStyle lineStyle,
    float borderWidth, Color color) {
        border.LineStyle = lineStyle;
        border.LineWidth = borderWidth;
        border.LineColor = color;
    }

Process.Start(new ProcessStartInfo(fileName) { UseShellExecute = true });
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Diagnostics
Imports System.Drawing

Private fileName As String = "Test.docx"
Using wordProcessor = New RichEditDocumentServer()
    Dim document As Document = wordProcessor.Document
    ' Generate a document with two sections and multiple pages in each section.
    Private Sub SurroundingSub()
        document.AppendText(vbFormFeed & vbFormFeed & vbFormFeed)
        document.Paragraphs.Append()
        document.AppendSection()
        document.AppendText(vbFormFeed & vbFormFeed)
    End Sub

    Dim firstSection As Section = document.Sections(0)
    Dim pageBorders1 As SectionPageBorders = firstSection.PageBorders

    ' Set page borders for the first page of the first section.
    SetPageBorders(pageBorders1.LeftBorder, BorderLineStyle.Single, 1F, Color.Red)
    SetPageBorders(pageBorders1.TopBorder, BorderLineStyle.Single, 1F, Color.Red)
    SetPageBorders(pageBorders1.RightBorder, BorderLineStyle.Single, 1F, Color.Red)
    SetPageBorders(pageBorders1.BottomBorder, BorderLineStyle.Single, 1F, Color.Red)
    pageBorders1.AppliesTo = PageBorderAppliesTo.FirstPage

    Dim secondSection As Section = document.Sections(1)
    Dim pageBorders2 As SectionPageBorders = secondSection.PageBorders

    ' Set page borders for all pages of the second section.
    SetPageBorders(pageBorders2.LeftBorder, BorderLineStyle.Double, 1.5F, Color.Green)
    SetPageBorders(pageBorders2.TopBorder, BorderLineStyle.Double, 1.5F, Color.Green)
    SetPageBorders(pageBorders2.RightBorder, BorderLineStyle.Double, 1.5F, Color.Green)
    SetPageBorders(pageBorders2.BottomBorder, BorderLineStyle.Double, 1.5F, Color.Green)
    pageBorders2.AppliesTo = PageBorderAppliesTo.AllPages
    pageBorders2.ZOrder = PageBorderZOrder.Back

    wordProcessor.SaveDocument(fileName, DocumentFormat.Docx)
End Using
Private Sub SetPageBorders(ByVal border As PageBorder, ByVal lineStyle As BorderLineStyle, ByVal borderWidth As Single, ByVal color As Color)
    border.LineStyle = lineStyle
    border.LineWidth = borderWidth
    border.LineColor = color
End Sub

Process.Start(New ProcessStartInfo(fileName) With {.UseShellExecute = True})

The following picture shows the resulting page borders:

See Also

SectionPageBorders Members

DevExpress.XtraRichEdit.API.Native Namespace