Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Word .NET
>
Tutorial
> Insert text box
The example shows you how to insert text box in a document.
C# example
using System; using Independentsoft.Office.Vml; using Independentsoft.Office.Word; namespace Sample { class Program { static void Main(string[] args) { WordDocument doc = new WordDocument(); Run textBoxRun = new Run(); textBoxRun.AddText("Simple text inside a textbox"); Paragraph textBoxParagraph = new Paragraph(); textBoxParagraph.Add(textBoxRun); TextBox textBox = new TextBox(); textBox.Content.Add(textBoxParagraph); ShapeTemplate shapeTemplate = new ShapeTemplate(); ShapeStyle shapeStyle = new ShapeStyle(); shapeStyle.Position = Position.Absolute; shapeStyle.Width = "100pt"; shapeStyle.Height = "75pt"; Shape shape = new Shape(shapeStyle); shape.Content.Add(textBox); VmlObject vmlObject = new VmlObject(); vmlObject.Content.Add(shape); Run run1 = new Run(); run1.Add(vmlObject); Paragraph paragraph1 = new Paragraph(); paragraph1.Add(run1); doc.Body.Add(paragraph1); doc.Save("c:\\test\\output.docx", true); } } }
VB example
Imports System Imports Independentsoft.Office.Vml Imports Independentsoft.Office.Word Module Module1 Sub Main(ByVal args() As String) Dim doc As WordDocument = New WordDocument() Dim textBoxRun As New Run() textBoxRun.AddText("Simple text inside a textbox") Dim textBoxParagraph As New Paragraph() textBoxParagraph.Add(textBoxRun) Dim textBox As New TextBox() textBox.Content.Add(textBoxParagraph) Dim shapeTemplate As New ShapeTemplate() Dim shapeStyle As New ShapeStyle() shapeStyle.Position = Position.Absolute shapeStyle.Width = "100pt" shapeStyle.Height = "75pt" Dim shape As New Shape(shapeStyle) shape.Content.Add(textBox) Dim vmlObject As New VmlObject() vmlObject.Content.Add(shape) Dim run1 As New Run() run1.Add(vmlObject) Dim paragraph1 As New Paragraph() paragraph1.Add(run1) doc.Body.Add(paragraph1) doc.Save("c:\test\output.docx", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*