Creates a new list that references a list style and adds it to the collection of lists in the document.
[Visual Basic]Overloads Public Function Add( _
ByVal
listStyle As
Style _
) As
List Parameters
- listStyle
- The list style.
Return Value
Thew newly created list.
Remarks
The newly created list references the list style. If you change the properties of the list style, it is reflected in the properties of the list. Vice versa, if you change the properties of the list, it is reflected in the properties of the list style.
Example
Shows how to create a list style and use it in a document.
[C#]
Document doc = new Document();
// Create a new list style.
// List formatting associated with this list style is default numbered.
Style listStyle = doc.Styles.Add(StyleType.List, "MyListStyle");
// This list defines the formatting of the list style.
// Note this list can not be used directly to apply formatting to paragraphs (see below).
List list1 = listStyle.List;
// Check some basic rules about the list that defines a list style.
Assert.AreEqual(true, list1.IsListStyleDefinition);
Assert.AreEqual(false, list1.IsListStyleReference);
Assert.AreEqual(true, list1.IsMultiLevel);
Assert.AreEqual(listStyle, list1.Style);
// Modify formatting of the list style to our liking.
for (int i = 0; i < list1.ListLevels.Count; i++)
{
ListLevel level = list1.ListLevels[i];
level.Font.Name = "Verdana";
level.Font.Color = Color.Blue;
level.Font.Bold = true;
}
// Add some text to our document and use the list style.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Using list style first time:");
// This creates a list based on the list style.
List list2 = doc.Lists.Add(listStyle);
// Check some basic rules about the list that references a list style.
Assert.AreEqual(false, list2.IsListStyleDefinition);
Assert.AreEqual(true, list2.IsListStyleReference);
Assert.AreEqual(listStyle, list2.Style);
// Apply the list that references the list style.
builder.ListFormat.List = list2;
builder.Writeln("Item 1");
builder.Writeln("Item 2");
builder.ListFormat.RemoveNumbers();
builder.Writeln("Using list style second time:");
// Create and apply another list based on the list style.
List list3 = doc.Lists.Add(listStyle);
builder.ListFormat.List = list3;
builder.Writeln("Item 1");
builder.Writeln("Item 2");
builder.ListFormat.RemoveNumbers();
builder.Document.Save(MyDir + "Lists.CreateAndUseListStyle Out.doc");[Visual Basic]
Dim doc As Document = New Document()
' Create a new list style.
' List formatting associated with this list style is default numbered.
Dim listStyle As Style = doc.Styles.Add(StyleType.List, "MyListStyle")
' This list defines the formatting of the list style.
' Note this list can not be used directly to apply formatting to paragraphs (see below).
Dim list1 As List = listStyle.List
' Check some basic rules about the list that defines a list style.
Assert.AreEqual(True, list1.IsListStyleDefinition)
Assert.AreEqual(False, list1.IsListStyleReference)
Assert.AreEqual(True, list1.IsMultiLevel)
Assert.AreEqual(listStyle, list1.Style)
' Modify formatting of the list style to our liking.
Dim i As Integer = 0
Do While i < list1.ListLevels.Count
Dim level As ListLevel = list1.ListLevels(i)
level.Font.Name = "Verdana"
level.Font.Color = Color.Blue
level.Font.Bold = True
i += 1
Loop
' Add some text to our document and use the list style.
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
builder.Writeln("Using list style first time:")
' This creates a list based on the list style.
Dim list2 As List = doc.Lists.Add(listStyle)
' Check some basic rules about the list that references a list style.
Assert.AreEqual(False, list2.IsListStyleDefinition)
Assert.AreEqual(True, list2.IsListStyleReference)
Assert.AreEqual(listStyle, list2.Style)
' Apply the list that references the list style.
builder.ListFormat.List = list2
builder.Writeln("Item 1")
builder.Writeln("Item 2")
builder.ListFormat.RemoveNumbers()
builder.Writeln("Using list style second time:")
' Create and apply another list based on the list style.
Dim list3 As List = doc.Lists.Add(listStyle)
builder.ListFormat.List = list3
builder.Writeln("Item 1")
builder.Writeln("Item 2")
builder.ListFormat.RemoveNumbers()
builder.Document.Save(MyDir & "Lists.CreateAndUseListStyle Out.doc")See Also
ListCollection Class | Aspose.Words.Lists Namespace | ListCollection.Add Overload List