How to set font size when created custom list style

Hi there,
I’ve created new list style by following code:

private List DefineNewListNumbering(Document doc)
{
    var list = doc.Lists.Add(ListTemplate.OutlineHeadingsLegal);
    // Level 1 labels will be "1".
    list.ListLevels[0].NumberFormat = "\x0000.";
    list.ListLevels[0].NumberStyle = NumberStyle.Arabic;
    list.ListLevels[0].Font.Size = 20;
    // Level 2 labels will be "1.1."
    list.ListLevels[1].NumberFormat = "\x0000.\x0001.";
    list.ListLevels[1].NumberStyle = NumberStyle.Arabic;
    list.ListLevels[1].Font.Size = 14;
    list.ListLevels[1].Font.Italic = false;
    // Level 3 labels will be "1.1.1.".
    list.ListLevels[2].NumberFormat = "\x0000.\x0001.\x0002.";
    list.ListLevels[2].NumberStyle = NumberStyle.Arabic;
    list.ListLevels[2].Font.Size = 11;
    // Level 4 labels will be "a.1.".
    list.ListLevels[3].NumberFormat = "\x0003.\x0000.";
    list.ListLevels[3].NumberStyle = NumberStyle.LowercaseLetter;
    // Make labels of all list levels bold.
    foreach (ListLevel level in list.ListLevels)
    {
        level.Font.Bold = true;
    }
    return list;
}

This code run very fun but font size of list level cannot match with my style.
This font style keeps default font. Heading 1 has font size 16 and heading 2 has font size 14.
Please help me to fix this issue.
Thanks,
Hanh

Hi Hanh,
Can you please share a couple of documents to show what you get after running your code and what is your expected output?
Best Regards,

Hi guys,

I just posted my expect out.
Please help me to view it and give me advances

Thanks,
Hanh

Hi Hanh,
Your document has many pages and lists. Can you please highlight which part of the document you are referring to? It would be great if you can copy your desired list in a new document and post that document with a single list only.
If you are trying to work with Table of Contents field, you can follow this example https://docs.aspose.com/words/net/working-with-table-of-contents/ to work with table of contents.
Best Regards,

Hi you guys,

Thanks for your feedback. Please see my expert list style bellow:

  1. Heading 1
    1.1. Heading 2
    1.1.2 Heading 3
  2. Heading 2.1
    2.1. Heading 2.1.2
    2.1.1. Heading 2.1.2

Right now, My above code is correctly with output. But now, Heading 2(eg: 1.1. Heading 2) is having font-italic default is true and Heading 3(eg: 1.1.2 Heading 3) is having font-size default is 10. I’m trying to change font-size and font-italic default to font-italic = false and fonts-size = 11. But It can’t be changed .
Please help me to fix it.

Many thanks,

Hi Hanh,
Your code generates attached list at my end. Can you please elaborate what problems you see in this output?
Best Regards,

Hi you guys,

Please see my attach file which contains output generated by my above code and my expert output.

Thanks,

Hi Hanh,
Thanks for the detailed description. We are working on updating your code according to your requirement and will update you soon.
Best Regards,

Hi Hanh,
You are using paragraph level styles for different levels of your desired list so you need to update these styles before adding text to your list. You can use following code to set styles and formatting for different levels of your required list.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
 
List list = doc.Lists.Add(ListTemplate.OutlineHeadingsLegal);
list.ListLevels[0].NumberFormat = "\x0000.";
list.ListLevels[0].NumberStyle = NumberStyle.Arabic;
Style styleLevel0 = doc.Styles["Heading 1"];
styleLevel0.Font.Size = 24;
styleLevel0.ListFormat.List = list;
styleLevel0.ListFormat.ListLevelNumber = 0;
Style styleLevel1 = doc.Styles["Heading 2"];
styleLevel1.Font.Italic = false;
styleLevel1.ListFormat.List = list;
styleLevel1.ListFormat.ListLevelNumber = 1;
builder.ParagraphFormat.Style = styleLevel0;
builder.Writeln("Level0 Text 1.");
builder.ParagraphFormat.Style = styleLevel1;
builder.Writeln("Level1 Text 1.");
builder.ParagraphFormat.Style = styleLevel0;
builder.Writeln("Level0 Text 2.");
builder.ParagraphFormat.Style = styleLevel1;
builder.Writeln("Level1 Text 2.");
builder.ParagraphFormat.Style = styleLevel1;
builder.Writeln("Level1 Text 3.");
builder.ListFormat.RemoveNumbers();
builder.ParagraphFormat.ClearFormatting();
builder.Document.Save("Lists Out.doc");

Best Regards,

Many thanks for your answer. This code is correct. :slight_smile: