[英]How change the color of a specific word in a string? vb.net
I have a problem with color of a specific word in a string. 我的字符串中的特定单词的颜色有问题。 I have my string like that:
我有我的字符串:
1) i Create a table like that: 1)我创建一个这样的表:
Dim SequenceTable As New DataTable
SequenceTable.Columns.Add("Paragraph", GetType(String))
SequenceTable.Columns.Add("Description", GetType(String))
SequenceTable.Columns.Add("ActivityName", GetType(String))
2) I get value Paragraph, Description, and activityName: 2)我得到值段落,描述和activityName:
If SequenceRow.IsNull("ActivityNumber") = False Then
ActivityNumber = SequenceRow.ActivityNumber
End If
If SequenceRow.IsNull("Specification") = False Then
Specification = SequenceRow.Specification
End If
If SequenceRow.IsNull("Dimension") = False Then
Paragraph = SequenceRow.Dimension
End If
3) I put all string in table: 3)我把所有字符串放在表中:
Cell = New TableCell
Cell.HorizontalAlign = HorizontalAlign.Left
Cell.Width = Unit.Percentage(16.5)
Cell.CssClass = "FormatTabel"
Cell.Text = Description
Cell.Font.Size = 6
Cell.Wrap = True
Row.Cells.Add(Cell)
My string in description 我在描述中的字符串
Description = "Presence and pictures required. Raw data and multiload required. "
I want the word pictures to be red and all word to be black? 我希望单词图片为红色,所有单词都是黑色的? But how can i set red color for word "pictures" and after put in table?
但是如何在单词“图片”中设置红色并放入表格后?
Thanks 谢谢
You can add <span/>
with formatted text using InnerHtml
in your cell instead Text
您可以在单元格中使用
InnerHtml
添加带有格式化文本的<span/>
,而不是Text
Cell = New TableCell
Cell.HorizontalAlign = HorizontalAlign.Left
Cell.Width = Unit.Percentage(16.5)
Cell.InnerHtml = "<span style='color: yellow'>" + "Presence" + "</span>" + "<span style='color: black'>" + "...black text" + "</span>";
Cell.Font.Size = 6
Cell.Wrap = True
Row.Cells.Add(Cell)
string AddColor(string Text, string word string color)
{
return Text.Replace(word, "<span color: '" + color + "'>"+word+"</span>")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.