Independentsoft
Home
Purchase
Support
Company
Contact
Word .NET
>
Tutorial
> Paragraph borders
The following example shows you how to add borders to a paragraph.
C# example
using System; using Independentsoft.Office.Word; namespace Sample { class Program { static void Main(string[] args) { WordDocument doc = new WordDocument(); // Create paragraph with borders Run run = new Run(); run.AddText("This paragraph has borders on all sides."); Paragraph paragraph = new Paragraph(); paragraph.Add(run); // Create borders string borderColor = "000000"; int borderWidth = 4; // size in eighths of a point TopBorder topBorder = new TopBorder(); topBorder.Style = StandardBorderStyle.SingleLine; topBorder.Color = borderColor; topBorder.Width = borderWidth; BottomBorder bottomBorder = new BottomBorder(); bottomBorder.Style = StandardBorderStyle.SingleLine; bottomBorder.Color = borderColor; bottomBorder.Width = borderWidth; LeftBorder leftBorder = new LeftBorder(); leftBorder.Style = StandardBorderStyle.SingleLine; leftBorder.Color = borderColor; leftBorder.Width = borderWidth; RightBorder rightBorder = new RightBorder(); rightBorder.Style = StandardBorderStyle.SingleLine; rightBorder.Color = borderColor; rightBorder.Width = borderWidth; paragraph.TopBorder = topBorder; paragraph.BottomBorder = bottomBorder; paragraph.LeftBorder = leftBorder; paragraph.RightBorder = rightBorder; // Create paragraph with bottom border only (horizontal line effect) Run run2 = new Run(); run2.AddText("This paragraph has only a bottom border."); Paragraph paragraph2 = new Paragraph(); paragraph2.Add(run2); BottomBorder bottomOnly = new BottomBorder(); bottomOnly.Style = StandardBorderStyle.SingleLine; bottomOnly.Color = "0000FF"; bottomOnly.Width = 8; paragraph2.BottomBorder = bottomOnly; doc.Body.Add(paragraph); doc.Body.Add(paragraph2); doc.Save("c:\\test\\output.docx", true); } } }
VB example
Imports System Imports Independentsoft.Office.Word Module Module1 Sub Main(ByVal args() As String) Dim doc As WordDocument = New WordDocument() ' Create paragraph with borders Dim run As Run = New Run() run.AddText("This paragraph has borders on all sides.") Dim paragraph As Paragraph = New Paragraph() paragraph.Add(run) ' Create borders Dim borderColor As String = "000000" Dim borderWidth As Integer = 4 ' size in eighths of a point Dim topBorder As TopBorder = New TopBorder() topBorder.Style = StandardBorderStyle.SingleLine topBorder.Color = borderColor topBorder.Width = borderWidth Dim bottomBorder As BottomBorder = New BottomBorder() bottomBorder.Style = StandardBorderStyle.SingleLine bottomBorder.Color = borderColor bottomBorder.Width = borderWidth Dim leftBorder As LeftBorder = New LeftBorder() leftBorder.Style = StandardBorderStyle.SingleLine leftBorder.Color = borderColor leftBorder.Width = borderWidth Dim rightBorder As RightBorder = New RightBorder() rightBorder.Style = StandardBorderStyle.SingleLine rightBorder.Color = borderColor rightBorder.Width = borderWidth paragraph.TopBorder = topBorder paragraph.BottomBorder = bottomBorder paragraph.LeftBorder = leftBorder paragraph.RightBorder = rightBorder ' Create paragraph with bottom border only (horizontal line effect) Dim run2 As Run = New Run() run2.AddText("This paragraph has only a bottom border.") Dim paragraph2 As Paragraph = New Paragraph() paragraph2.Add(run2) Dim bottomOnly As BottomBorder = New BottomBorder() bottomOnly.Style = StandardBorderStyle.SingleLine bottomOnly.Color = "0000FF" bottomOnly.Width = 8 paragraph2.BottomBorder = bottomOnly doc.Body.Add(paragraph) doc.Body.Add(paragraph2) doc.Save("c:\test\output.docx", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*