gpt4 book ai didi

c# - 如何在 C# Winform 中更改文本框中某些子字符串的字体颜色?

转载 作者:太空狗 更新时间:2023-10-30 00:42:41 24 4
gpt4 key购买 nike

如果我想上传一个文本文件到文本框中,并想用字体颜色变化突出显示某些单词,我知道我需要写 TextBox.ForeColor = Color.SomeColor;
但是如果我想要不是所有的文本都是相同颜色,只有一些子字符串。
我该怎么做?

最佳答案

通过Pieter Joost van de Sande检查答案.

You can't do this in the TextBox control, only in the RichTextBox control.

if( myRichTextBox.TextLenght >= 5 )
{
myRichTextBox.Select( 0, 5 );
myRichTextBox.SelectionColor = Color.Green;
}

if( myRichTextBox.TextLenght >= 15 )
{
myRichTextBox.Select( 10, 15 );
myRichTextBox.SelectionColor = Color.Red;
}

关于c# - 如何在 C# Winform 中更改文本框中某些子字符串的字体颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14119947/

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