简体   繁体   中英

How do I add circle list style to a bullet list in RichTextBox?

Running into an issue with adding a "circle" bullet style to my list. I have tried coding it into an WebBrowser object and then passing that into the RTB, I have also tried richtextbox.rtf with no success.

For the HTML I tried:

WebBrowser webBrowser1 = new WebBrowser();
string content;
        content = "<html><body><font size=4><b>" + projects[0].ProjectName.ToString() + "</font></b> <br> <u>Description</u>: "
            + projects[0].Objective.ToString() + "<br><u>Benefits</u>: <ul style=\"list-style-type:circle\"><li>Near-Term --</li>"
            + "<ul style=\"list-style-type:circle\"><li type=\"circle\">" + projects[1].ShortTerm.ToString() + "</li></ul></ul></body></html>";
webBrowser1.Navigate("about:blank");
webBrowser1.Document.Write(content);
webBrowser1.Document.ExecCommand("SelectAll", false, null);
webBrowser1.Document.ExecCommand("Copy", false, null);
projectsEditor1.RichTextBox.Paste();

This will output everything correctly, however the nested bullet which should be an open circle is just the default "disc" value. I tried putting the type in both li and ul with no luck on either. This example just shows me doing it on both hoping it would work. I've seen that RTB's "only support" disc value. But if I take a bullet list from word and copy/paste it into my RTB it displays the circle bullet. Is it at all possible to program the circle value into a RTB?

My current code because HTML didn't work is just to do it like this:

                projectsEditor1.RichTextBox.SelectionBullet = true;
                projectsEditor1.RichTextBox.BulletIndent = 20;
                projectsEditor1.RichTextBox.AppendText("Near-term –");
                projectsEditor1.RichTextBox.AppendText(Environment.NewLine);
                projectsEditor1.RichTextBox.SelectionBullet = false;
                projectsEditor1.RichTextBox.SelectionFont = new System.Drawing.Font("Calibri", 11.0F, FontStyle.Regular);
                projectsEditor1.RichTextBox.SelectionIndent = 45;
                projectsEditor1.RichTextBox.SelectionBullet = true;
                projectsEditor1.RichTextBox.BulletIndent = 20;
                projectsEditor1.RichTextBox.SelectionFont = new System.Drawing.Font("Calibri", 11.0F, FontStyle.Regular);
                projectsEditor1.RichTextBox.AppendText(project.ShortTerm.ToString());
                projectsEditor1.RichTextBox.AppendText(Environment.NewLine);
                projectsEditor1.RichTextBox.SelectionBullet = false;
                projectsEditor1.RichTextBox.SelectionIndent = 0;

But again this just produces the same result as the HTML.

Current Output:

在此处输入图片说明

Desired Output:

在此处输入图片说明

Like I said what i've been able to find says RTB doesn't support anything other than default bullets but you can paste them into the RTB, so it makes me think it can be done.

You can use Unicode character:

projectsEditor1.RichTextBox.BulletIndent = 20;
projectsEditor1.RichTextBox.AppendText("Near-term –");
projectsEditor1.RichTextBox.AppendText(Environment.NewLine);
//projectsEditor1.RichTextBox.AppendText("\u25E6".PadLeft(20));
projectsEditor1.RichTextBox.AppendText("\t\u25E6");
projectsEditor1.RichTextBox.AppendText("Some Benefits...");

Edit : A workaround to your problem may be,

 var benefits = "string1\nstring2\nstring3";
 var text = benefits.Split(new char[] { '\n' })
                    .Select(t => 
                    string.Format("{0}{1}{2}", "\t\u25E6 ", t, "\n"))
                    .ToArray();
 benefits = string.Join("", text);

 // Then
 projectsEditor1.RichTextBox.AppendText(benefits);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM