我有一个文本,有行,带有“#”的字符串。如何使所有文字变黑,只有这些线条变绿?
答案 0 :(得分:1)
您可以按如下方式实现:
String[] lines = ...
foreach (String line in lines)
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;
if (line.StartsWith("#"))
box.SelectionColor = Color.Red;
else
box.SelectionColor = Color.Black;
box.AppendText(line + Environment.NewLine);
}