Vladut Vladut - 21 days ago 6
Vb.net Question

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:

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:

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:

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

mww mww
Answer

You can add <span/> with formatted text using InnerHtml in your cell instead 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)