gpt4 book ai didi

c# - 多色文本框 C#

转载 作者:可可西里 更新时间:2023-11-01 03:11:56 24 4
gpt4 key购买 nike

我想在文本框中以 2 种颜色显示文本,例如 1 行红色 2 蓝色,如果我使用 name.ForeColor = Color.Red; 所有文本都会改变颜色,但我希望它会改变只有 1 种线条颜色。

最佳答案

为此使用 RichTextBox,这是 Nathan Baulch 的扩展方法

public static class RichTextBoxExtensions
{
public static void AppendText(this RichTextBox box, string text, Color color)
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;

box.SelectionColor = color;
box.AppendText(text);
box.SelectionColor = box.ForeColor;
}
}

阅读更多 here

关于c# - 多色文本框 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10587715/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com