c#中字符串的粗体部分

时间:2016-11-14 13:49:17

标签: c# textbox

我尝试使用此方法,但它仅在richTextBox中第一次显示textToMark时更改,并且我希望每次public static void ChangeTextcolor(string textToMark, Color color, RichTextBox richTextBox) { int startIndex = 0; string text = richTextBox.Text; startIndex = text.IndexOf(textToMark); System.Drawing.Font newFont = new Font("Verdana", 10f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 178, false); try { foreach (string line in richTextBox.Lines) { if (line.Contains(textToMark)) { richTextBox.Select(startIndex, textToMark.Length); richTextBox.SelectionColor = color; richTextBox.SelectionFont = newFont; } } } catch{ } } 包含时更改{/ 1}}:

data
你能帮帮我吗? 感谢

1 个答案:

答案 0 :(得分:-1)

您可以使用RichTextBox Control。 Formatting Characters in Bold in a RichTextBox Control (Visual C#)

richTextBox1.Rtf = @"{\rtf1\ansi This is in \b bold\b0.}";