Class BlockContentControl
Represents a block content control in the Word document.
Inheritance
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Base.dll
Syntax
public class BlockContentControl : TextBodyItem, IXDLSSerializable, ITextBodyItem, IWidgetContainer, IWidget, IBlockContentControl, ICompositeEntity, IEntity
Constructors
BlockContentControl(WordDocument)
Initializes a new instance of the BlockContentControl class.
Declaration
public BlockContentControl(WordDocument doc)
Parameters
Type | Name | Description |
---|---|---|
WordDocument | doc | The Word document. |
Examples
The following example illustrates how to initializes a new instance of the BlockContentControl.
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
BlockContentControl control = new BlockContentControl(document);
//Adds new paragraph to the section.
WParagraph paragraph = new WParagraph(control.Document);
//Adds new text to the content control.
paragraph.AppendText("Block content control");
//Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph);
//Sets title of the block content control.
control.ContentControlProperties.Title = "Rich text content control";
//Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
Dim document As New WordDocument()
'Adds new section to the document
Dim section As IWSection = document.AddSection()
Dim control As New BlockContentControl(document)
'Adds new paragraph to the section.
Dim paragraph As New WParagraph(control.Document)
'Adds new text to the content control.
paragraph.AppendText("Block content control")
'Adds paragraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph)
'Sets title of the block content control.
control.ContentControlProperties.Title = "Rich text content control"
'Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
BlockContentControl(WordDocument, ContentControlType)
Initializes a new instance of the BlockContentControl class.
Declaration
public BlockContentControl(WordDocument doc, ContentControlType controlType)
Parameters
Type | Name | Description |
---|---|---|
WordDocument | doc | The Word document. |
ContentControlType | controlType | The content control type. |
Properties
BreakCharacterFormat
Gets the character format of the content control. Read-only.
Declaration
public WCharacterFormat BreakCharacterFormat { get; }
Property Value
Type | Description |
---|---|
WCharacterFormat | The WCharacterFormat object that specifies the character format. |
ChildEntities
Gets the content control child entities.
Declaration
public EntityCollection ChildEntities { get; }
Property Value
Type | Description |
---|---|
EntityCollection | The child entities of the WTextBody |
Examples
The following example illustrates how to get the child entities of the content control. ///
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
BlockContentControl control = new BlockContentControl(document, ContentControlType.RichText);
//Adds new paragraph to the section.
WParagraph paragraph = new WParagraph(control.Document);
//Adds new text to the content control.
paragraph.AppendText("Block content control");
//Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph);
//Sets title of the block content control.
control.ContentControlProperties.Title = "Rich text content control";
//Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
Dim document As New WordDocument()
'Adds new section to the document
Dim section As IWSection = document.AddSection()
Dim control As New BlockContentControl(document, ContentControlType.RichText)
'Adds new paragraph to the section.
Dim paragraph As New WParagraph(control.Document)
'Adds new text to the content control.
paragraph.AppendText("Block content control")
'Adds paragraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph)
'Sets title of the block content control.
control.ContentControlProperties.Title = "Rich text content control"
'Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
ContentControlProperties
Gets the content control properties. Read-only.
Declaration
public ContentControlProperties ContentControlProperties { get; }
Property Value
Type | Description |
---|---|
ContentControlProperties | The ContentControlProperties object that specifies the content control properties. |
Examples
The following example illustrates how to set the properties for content control.
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
BlockContentControl control = new BlockContentControl(document, ContentControlType.RichText);
//Adds new paragraph to the section.
WParagraph paragraph = new WParagraph(control.Document);
//Adds new text to the content control.
paragraph.AppendText("Block content control");
//Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph);
//Sets title of the block content control.
control.ContentControlProperties.Title = "Rich text content control";
//Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
Dim document As New WordDocument()
'Adds new section to the document
Dim section As IWSection = document.AddSection()
Dim control As New BlockContentControl(document, ContentControlType.RichText)
'Adds new paragraph to the section.
Dim paragraph As New WParagraph(control.Document)
'Adds new text to the content control.
paragraph.AppendText("Block content control")
'Adds paragraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph)
'Sets title of the block content control.
control.ContentControlProperties.Title = "Rich text content control"
'Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
EntityType
Gets the type of the entity.
Declaration
public override EntityType EntityType { get; }
Property Value
Type | Description |
---|---|
EntityType | The EntityType of the current item. |
Overrides
TextBody
Gets the block control text body. Read-only.
Declaration
public WTextBody TextBody { get; }
Property Value
Type | Description |
---|---|
WTextBody |
Examples
The following example illustrates how to get the text body of the content control.
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
BlockContentControl control = new BlockContentControl(document, ContentControlType.RichText);
//Adds new paragraph to the section.
WParagraph paragraph = new WParagraph(control.Document);
//Adds new text to the content control.
paragraph.AppendText("Block content control");
//Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph);
//Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
Dim document As New WordDocument()
'Adds new section to the document
Dim section As IWSection = document.AddSection()
Dim control As New BlockContentControl(document, ContentControlType.RichText)
'Adds new paragraph to the section.
Dim paragraph As New WParagraph(control.Document)
'Adds new text to the content control.
paragraph.AppendText("Block content control")
'Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph)
'Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
WidgetCollection
Gets the child items
Declaration
protected IEntityCollectionBase WidgetCollection { get; }
Property Value
Type | Description |
---|---|
IEntityCollectionBase |
WidgetInnerCollection
Gets the child entity collection.
Declaration
public EntityCollection WidgetInnerCollection { get; }
Property Value
Type | Description |
---|---|
EntityCollection |
Methods
CloneImpl()
Creates a duplicate of the entity.
Declaration
protected override object CloneImpl()
Returns
Type | Description |
---|---|
System.Object |
Overrides
CreateLayoutInfo()
Creates the layout information.
Declaration
protected override void CreateLayoutInfo()
Overrides
Find(String, Boolean, Boolean)
Declaration
public TextSelection Find(string given, bool caseSensitive, bool wholeWord)
Parameters
Type | Name | Description |
---|---|---|
System.String | given | |
System.Boolean | caseSensitive | |
System.Boolean | wholeWord |
Returns
Type | Description |
---|---|
TextSelection |
Find(Regex)
Gets the first entry of given regex in the content control.
Declaration
public override TextSelection Find(Regex pattern)
Parameters
Type | Name | Description |
---|---|---|
System.Text.RegularExpressions.Regex | pattern | The pattern. |
Returns
Type | Description |
---|---|
TextSelection | Text selection with this pattern. |
Overrides
Examples
The following example illustrates how to find the text based on given regex pattern.
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
BlockContentControl control = new BlockContentControl(document, ContentControlType.RichText);
//Adds new paragraph to the section.
WParagraph paragraph = new WParagraph(control.Document);
//Adds new text to the content control.
paragraph.AppendText(@"the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions.");
//Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph);
//Find the text based on regex.
TextSelection text = control.Find(new Regex("instructions"));
//Replaces all entries of given string with replace string.
control.Replace(new Regex(@"requirements"), text);
//Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
Dim document As New WordDocument()
'Adds new section to the document
Dim section As IWSection = document.AddSection()
Dim control As New BlockContentControl(document, ContentControlType.RichText)
'Adds new paragraph to the section.
Dim paragraph As New WParagraph(control.Document)
'Adds new text to the content control.
paragraph.AppendText("the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions.")
'Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph)
'Find the text based on regex.
Dim text As TextSelection = control.Find(New Regex("instructions"))
'Replaces all entries of given string with replace string.
control.Replace(New Regex("requirements"), text)
'Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
Replace(String, TextSelection, Boolean, Boolean)
Declaration
public int Replace(string given, TextSelection textSelection, bool caseSensitive, bool wholeWord)
Parameters
Type | Name | Description |
---|---|---|
System.String | given | |
TextSelection | textSelection | |
System.Boolean | caseSensitive | |
System.Boolean | wholeWord |
Returns
Type | Description |
---|---|
System.Int32 |
Replace(String, TextSelection, Boolean, Boolean, Boolean)
Replaces all entries of given string with TextRangesHolder, taking into consideration caseSensitive and wholeWord options.
Declaration
public int Replace(string given, TextSelection textSelection, bool caseSensitive, bool wholeWord, bool saveFormatting)
Parameters
Type | Name | Description |
---|---|---|
System.String | given | The given. |
TextSelection | textSelection | The text selection. |
System.Boolean | caseSensitive | if it specifies case sensitive, set to |
System.Boolean | wholeWord | if it specifies to search a whole word, set to |
System.Boolean | saveFormatting | if it specifies save source formatting, set to |
Returns
Type | Description |
---|---|
System.Int32 | The integer that represents the count of the replacements made. |
Examples
The following example illustrates how to replaces all entries of given string with TextRangesHolder, taking into consideration caseSensitive and wholeWord options.
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
BlockContentControl control = new BlockContentControl(document, ContentControlType.RichText);
//Adds new paragraph to the section.
WParagraph paragraph = new WParagraph(control.Document);
//Adds new text to the content control.
paragraph.AppendText(@"the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions.");
//Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph);
//Find the text based on regex.
TextSelection text = control.Find(new Regex("instructions"));
//Replaces all entries of given string with replace string.
control.Replace("requirements", text, false, true, true);
//Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
Dim document As New WordDocument()
'Adds new section to the document
Dim section As IWSection = document.AddSection()
Dim control As New BlockContentControl(document, ContentControlType.RichText)
'Adds new paragraph to the section.
Dim paragraph As New WParagraph(control.Document)
'Adds new text to the content control.
paragraph.AppendText("the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions.")
'Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph)
'Find the text based on regex.
Dim text As TextSelection = control.Find(New Regex("instructions"))
'Replaces all entries of given string with replace string.
control.Replace(New Regex("requirements"), text, false, true, true)
'Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
Replace(String, String, Boolean, Boolean)
Declaration
public override int Replace(string given, string replace, bool caseSensitive, bool wholeWord)
Parameters
Type | Name | Description |
---|---|---|
System.String | given | |
System.String | replace | |
System.Boolean | caseSensitive | |
System.Boolean | wholeWord |
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
Replace(Regex, TextSelection)
Replaces the regular expression with a text selection.
Declaration
public override int Replace(Regex pattern, TextSelection textSelection)
Parameters
Type | Name | Description |
---|---|---|
System.Text.RegularExpressions.Regex | pattern | The System.Text.RegularExpressions.Regex used to find the text. |
TextSelection | textSelection | The TextSelection which specifies the text to replace. |
Returns
Type | Description |
---|---|
System.Int32 | The integer that represents the count of the replacements made. |
Overrides
Examples
The following example illustrates how to replace the text based on the given regex pattern.
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
BlockContentControl control = new BlockContentControl(document, ContentControlType.RichText);
//Adds new paragraph to the section.
WParagraph paragraph = new WParagraph(control.Document);
//Adds new text to the content control.
paragraph.AppendText(@"the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions.");
//Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph);
//Find the text based on regex.
TextSelection text = control.Find(new Regex("instructions"));
//Replaces all entries of given string with replace string.
control.Replace(new Regex(@"requirements"), text);
//Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
Dim document As New WordDocument()
'Adds new section to the document
Dim section As IWSection = document.AddSection()
Dim control As New BlockContentControl(document, ContentControlType.RichText)
'Adds new paragraph to the section.
Dim paragraph As New WParagraph(control.Document)
'Adds new text to the content control.
paragraph.AppendText("the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions.")
'Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph)
'Find the text based on regex.
Dim text As TextSelection = control.Find(New Regex("instructions"))
'Replaces all entries of given string with replace string.
control.Replace(New Regex("requirements"), text)
'Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
Replace(Regex, TextSelection, Boolean)
Replaces all entries of given regular expression with TextRangesHolder.
Declaration
public override int Replace(Regex pattern, TextSelection textSelection, bool saveFormatting)
Parameters
Type | Name | Description |
---|---|---|
System.Text.RegularExpressions.Regex | pattern | The pattern. |
TextSelection | textSelection | The text selection. |
System.Boolean | saveFormatting | if it specifies save source formatting, set to |
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
Examples
The following example illustrates how to replace all entries of given regular expression with TextRangesHolder.
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
BlockContentControl control = new BlockContentControl(document, ContentControlType.RichText);
//Adds new paragraph to the section.
WParagraph paragraph = new WParagraph(control.Document);
//Adds new text to the content control.
paragraph.AppendText(@"the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions.");
//Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph);
//Find the text based on regex.
TextSelection text = control.Find(new Regex("instructions"));
//Replaces all entries of given string with replace string.
control.Replace(new Regex(@"requirements"), text, true);
//Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
Dim document As New WordDocument()
'Adds new section to the document
Dim section As IWSection = document.AddSection()
Dim control As New BlockContentControl(document, ContentControlType.RichText)
'Adds new paragraph to the section.
Dim paragraph As New WParagraph(control.Document)
'Adds new text to the content control.
paragraph.AppendText("the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions.")
'Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph)
'Find the text based on regex.
Dim text As TextSelection = control.Find(New Regex("instructions"))
'Replaces all entries of given string with replace string.
control.Replace(New Regex("requirements"), text, true)
'Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
Replace(Regex, String)
Replaces all entries of given regular expression with replace string.
Declaration
public override int Replace(Regex pattern, string replace)
Parameters
Type | Name | Description |
---|---|---|
System.Text.RegularExpressions.Regex | pattern | The System.Text.RegularExpressions.Regex used to find the text. |
System.String | replace | The string specifies the text to replace. |
Returns
Type | Description |
---|---|
System.Int32 | The integer that represents the count of the replacements made. |
Overrides
Examples
The following example illustrates how to replace the text based on the given regex pattern.
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
BlockContentControl control = new BlockContentControl(document, ContentControlType.RichText);
//Adds new paragraph to the section.
WParagraph paragraph = new WParagraph(control.Document);
//Adds new text to the content control.
paragraph.AppendText(@"the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions.");
//Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph);
//Find the text based on regex.
TextSelection text = control.Find(new Regex("instructions"));
//Replaces all entries of given string with replace string.
control.Replace(new Regex(@"requirements"), text);
//Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
Dim document As New WordDocument()
'Adds new section to the document
Dim section As IWSection = document.AddSection()
Dim control As New BlockContentControl(document, ContentControlType.RichText)
'Adds new paragraph to the section.
Dim paragraph As New WParagraph(control.Document)
'Adds new text to the content control.
paragraph.AppendText("the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions.")
'Adds pagagraph into the Block content control.
control.TextBody.ChildEntities.Add(paragraph)
'Find the text based on regex.
Dim text As TextSelection = control.Find(New Regex("instructions"))
'Replaces all entries of given string with replace string.
control.Replace(New Regex("requirements"), text)
'Adds content control into the document.
document.LastSection.Body.ChildEntities.Add(control)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()