【发布时间】:2018-03-22 08:17:35
【问题描述】:
我有以下问题:在我的 C# 程序中,我有一个函数可以计算项目并将它们以 Windows 形式显示在 x/y 等文本框中。
我想突出显示整行
- 如果 x = y 则为绿色
- 如果 x != y 则为橙色
- 如果为 0 / y 则为红色
例子:
-
10/10 Items应以绿色突出显示 -
4/10 Items应以橙色突出显示 -
0/10 Items应以红色突出显示
感谢您的帮助 :)
工作代码:
我在 oder 中使用了一个富文本框来突出显示某些行:
Match search1 = Regex.Match(txt_result.Lines[i], @"(?<= wurde )(.*)(?= \/ )");
Match search2 = Regex.Match(txt_result.Lines[i], @"(?<= \/ )(.*)(?= in )");
if (search1.Value == search2.Value && search1.Value!="")
{
int c0 = txt_result.GetFirstCharIndexFromLine(i );
int c1 = txt_result.GetFirstCharIndexFromLine(i + 1);
if (c1 < 0) c1 = txt_result.Text.Length;
txt_result.SelectionStart = c0;
txt_result.SelectionLength = c1 - c0;
if (txt_result.SelectedText.Contains(search1.Value))
txt_result.SelectionColor = Color.Green;
}
【问题讨论】:
-
ASP.Net?吗?窗体?银光?
-
你能分享你的C#代码吗?
-
@ZoharPeled C#.Net 文本框采用基本形式
-
@Saadi 我不知道如何开始
-
控件错误,TextBox无法显示不同颜色的文本。改用 RichTextBox,更改 SelectionColor 属性(不是拼写错误)。请考虑使用 ListView,允许用户编辑此文本不太可能有用。