| |
 |
How to: Create Bulleted List in Code
This example illustrates how to create a standard bulleted list in code.
- Add a new AbstractNumberingList instance to the Document.AbstractNumberingLists collection
- Specify a NumberingListBase.NumberingType property, so that it equals the NumberingFormat.Bullet value.
- For each list level, specify the paragraph characteristics using the ListLevel.ParagraphProperties property. Set the left indentation (the ParagraphPropertiesBase.LeftIndent property) so that each level has a different offset from the left. To specify a symbol that will be used to mark a list item, set the font via the ListLevel.CharacterProperties property and the character via the ListLevelProperties.DisplayFormatString property.
- Use the Add method of the collection of lists in the document (accessible via the Document.NumberingLists property) to add a list definition to the document. The parameter is the index of an abstract numbering list created previously. The Add method creates a pattern that can be applied to a paragraph so that the paragraph looks like a list item.
- To include a paragraph in a bulleted list, set the Paragraph.ListIndex property of a paragraph to the index of a list in the document and specify the Paragraph.ListLevel property.
List.cs |
document.BeginUpdate();
AbstractNumberingList list = document.AbstractNumberingLists.Add();
list.NumberingType = NumberingType.Bullet;
ListLevel level = list.Levels[0];
CreateBulletedListHelper.AdjustLevelProperties(level, 100, 75, NumberingFormat.Decimal, new string('\u00B7', 1));
level = list.Levels[1];
CreateBulletedListHelper.AdjustLevelProperties(level, 300, 150, NumberingFormat.DecimalEnclosedParenthses, new string('\u006F', 1));
level = list.Levels[2];
CreateBulletedListHelper.AdjustLevelProperties(level, 450, 220, NumberingFormat.UpperRoman, new string('\u00B7', 1));
document.NumberingLists.Add(0);
document.EndUpdate();
document.AppendText("Line 1\nLine 2\nLine 3");
document.BeginUpdate();
ParagraphCollection paragraphs = document.Paragraphs;
foreach (Paragraph pgf in paragraphs) {
pgf.ListIndex = 0;
pgf.ListLevel = 0;
}
paragraphs[1].ListLevel = 1;
paragraphs[2].ListLevel = 2;
document.EndUpdate();
class CreateBulletedListHelper {
public static void AdjustLevelProperties(ListLevel level, int leftIndent, int firstLineIndent, NumberingFormat format, string displayFormat) {
level.CharacterProperties.FontName = "Symbol";
level.ParagraphProperties.LeftIndent = leftIndent;
level.ParagraphProperties.FirstLineIndentType = ParagraphFirstLineIndent.Hanging;
level.ParagraphProperties.FirstLineIndent = firstLineIndent;
level.Start = 1;
level.NumberingFormat = format;
level.DisplayFormatString = displayFormat;
}
}
|
List.vb |
document.BeginUpdate()
' Define an abstract list that is the pattern for lists used in the document.
Dim list As AbstractNumberingList = document.AbstractNumberingLists.Add()
list.NumberingType = NumberingType.Bullet
' Specify parameters for each list level.
Dim level As ListLevel = list.Levels(0)
CreateBulletedListHelper.AdjustLevelProperties(level, 100, 75, NumberingFormat.Decimal, New String(ChrW(&H00B7), 1))
level = list.Levels(1)
CreateBulletedListHelper.AdjustLevelProperties(level, 300, 150, NumberingFormat.DecimalEnclosedParenthses, New String(ChrW(&H006F), 1))
level = list.Levels(2)
CreateBulletedListHelper.AdjustLevelProperties(level, 450, 220, NumberingFormat.UpperRoman, New String(ChrW(&H00B7), 1))
' Create a list for use in the document. It is based on a previously defined abstract list with ID = 0.
document.NumberingLists.Add(0)
document.EndUpdate()
document.AppendText("Line 1" & vbLf & "Line 2" & vbLf & "Line 3")
' Convert paragraphs to list items.
document.BeginUpdate()
Dim paragraphs As ParagraphCollection = document.Paragraphs
For Each pgf As Paragraph In paragraphs
pgf.ListIndex = 0
pgf.ListLevel = 0
Next pgf
paragraphs(1).ListLevel = 1
paragraphs(2).ListLevel = 2
document.EndUpdate()
Private Class CreateBulletedListHelper
Public Shared Sub AdjustLevelProperties(ByVal level As ListLevel, ByVal leftIndent As Integer, ByVal firstLineIndent As Integer, ByVal format As NumberingFormat, ByVal displayFormat As String)
level.CharacterProperties.FontName = "Symbol"
level.ParagraphProperties.LeftIndent = leftIndent
level.ParagraphProperties.FirstLineIndentType = ParagraphFirstLineIndent.Hanging
level.ParagraphProperties.FirstLineIndent = firstLineIndent
level.Start = 1
level.NumberingFormat = format
level.DisplayFormatString = displayFormat
End Sub
End Class
|
Is this topic helpful?
Additional Feedback
Close
|