2016-11-18 93 views
1

我有一个字符串中特定单词的颜色问题。 我有我的字符串这样的:如何更改字符串中特定单词的颜色? vb.net

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)我得到价值段落,描述和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将所有字符串放在表格中:

    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) 

我在描述中的字符串

Description = "Presence and pictures required. Raw data and multiload required. " 

我想单词图片是红色的,所有单词都是黑色的?但是,我怎么能设置单词“图片”的红色和放在桌子后?

感谢

回答

3

您可以在您使用细胞代替InnerHtmlText

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) 
0
string AddColor(string Text, string word string color) 
{ 
    return Text.Replace(word, "<span color: '" + color + "'>"+word+"</span>") 
} 
+0

您还可以将此作为这将更加方便的扩展方法格式化文本并添加<span/>。 –

相关问题