代码之家  ›  专栏  ›  技术社区  ›  Mohammad

更改字符的颜色

  •  1
  • Mohammad  · 技术社区  · 15 年前

    如何使用c_更改字符串中字符的颜色? 对前来说,把D变成红色,其余的保持黑色。

    我正在使用WinForms,我尝试在文本框中显示它,我也可以使用RichTextBox。

    3 回复  |  直到 15 年前
        1
  •  3
  •   Albin Sunnanbo    15 年前

    你至少可以用richtextbox来实现。

    // Save selection
    var oldStart = richTextBox1.SelectionStart;
    var oldLength = richTextBox1.SelectionLength;
    
    // Select the text to change
    richTextBox1.Select(richTextBox1.TextLength - 1, 1);
    // Change color
    richTextBox1.SelectionColor = Color.Red;
    
    // Restore selection
    richTextBox1.Select(oldStart, oldLength);
    
        2
  •  0
  •   TomTom    15 年前

    你没有。字符串没有颜色。字符串的表示可能有颜色,但这不是您在字符串中确定的颜色。

        3
  •  0
  •   Dan J    15 年前