有没有办法在字符串数组的一个元素中插入颜色格式?
Is there a way to insert color formatting in one element of a string array?
假设我在此处显示了字符串数组的输出:
ProductID was = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, ,
我想用红色标记第 15 个元素(即上面的第 16 个元素),将其余元素标记为黑色。孤独的红色数字基于 ProductId
.
的值
这是我的代码:
string[] indices = new string[20];
string[] indices2 = new string[20];
for (int i = 0; i < allProducts.Count; i++)
{
indices[i] = Convert.ToString(allProducts[i].ProductId); //this holds the values shown above
indices2[i] = Convert.ToString(allProducts[i].CategoryId);
}
lbl_Indices.Text = "ProductID was = " + string.Join(", ", indices); //this is the output.
lbl_Indices2.Text = "CategoryID was = " + string.Join(", ", indices2);
我怎样才能达到预期的效果?或者我必须改用 RichTextBox
吗? (无需编写代码,我会这样做——只要告诉我最合适的方法即可。谢谢。)
RichTextBox
不存在于网页上,这是针对桌面应用程序的。
在网页中,您使用 html,在您的情况下,您需要使用 html 代码扭曲数字,使其变为红色。这是一个简单的例子,用
包裹起来
<span style="color:red;">16</span>
假设我在此处显示了字符串数组的输出:
ProductID was = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, ,
我想用红色标记第 15 个元素(即上面的第 16 个元素),将其余元素标记为黑色。孤独的红色数字基于 ProductId
.
这是我的代码:
string[] indices = new string[20];
string[] indices2 = new string[20];
for (int i = 0; i < allProducts.Count; i++)
{
indices[i] = Convert.ToString(allProducts[i].ProductId); //this holds the values shown above
indices2[i] = Convert.ToString(allProducts[i].CategoryId);
}
lbl_Indices.Text = "ProductID was = " + string.Join(", ", indices); //this is the output.
lbl_Indices2.Text = "CategoryID was = " + string.Join(", ", indices2);
我怎样才能达到预期的效果?或者我必须改用 RichTextBox
吗? (无需编写代码,我会这样做——只要告诉我最合适的方法即可。谢谢。)
RichTextBox
不存在于网页上,这是针对桌面应用程序的。
在网页中,您使用 html,在您的情况下,您需要使用 html 代码扭曲数字,使其变为红色。这是一个简单的例子,用
包裹起来<span style="color:red;">16</span>