简体   繁体   English

如何在RichTextBox的项目符号列表中添加圈子列表样式?

[英]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. 我尝试将其编码为WebBrowser对象,然后将其传递给RTB,但我也尝试了richtextbox.rtf,但未成功。

For the HTML I tried: 对于HTML,我尝试过:

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. 这将正确输出所有内容,但是嵌套的项目符号(应为空心圆)只是默认的“ disc”值。 I tried putting the type in both li and ul with no luck on either. 我尝试将类型同时放入li和ul中,但都没有运气。 This example just shows me doing it on both hoping it would work. 这个例子仅说明了我希望两者都能起作用。 I've seen that RTB's "only support" disc value. 我已经看到RTB的“仅支持”光盘价值。 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? 是否可以将圆值编程到RTB中?

My current code because HTML didn't work is just to do it like this: 我当前的代码因为HTML无效,所以只能这样做:

                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. 但这又产生了与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. 就像我说的那样,我发现RTB除默认项目符号外不支持任何其他功能,但您可以将其粘贴到RTB中,因此我认为可以做到。

You can use Unicode character: 您可以使用Unicode字符:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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