Preeti
Preeti

Reputation: 1386

Setting different color for each line in multiline TEXTBOX

My Code:

For Each dr In dt.Rows()
  If (cnt = 0) Then
     tx_control2.Text = dr("Name").ToString.Trim
  Else
     tx_control2.Text = tx_control2.Text + Environment.NewLine + dr("Name").ToString.Trim
  End If
  cnt = cnt + 1

Next ' for row

Using above code to add all names from datatable to TEXTBOX using Environment.NewLine. This is adding all names in TEXTBOX.Now I want different color for alternate names.

I used :

tx_control2.ForeColor = Color.Maroon

But above solution change the color of all names.

I looking for solution.

Thanks.

Upvotes: 1

Views: 6057

Answers (2)

Bala R
Bala R

Reputation: 108937

It's not possible with a TextBox. You'll have to use a RichTextBox for that.

Upvotes: 1

Blindy
Blindy

Reputation: 67362

Use a rich text box instead, normal text boxes don't provide the kind of control you need.

Upvotes: 0

Related Questions