开发者

Setting different color for each line in multiline TEXTBOX

开发者 https://www.devze.com 2023-02-18 08:35 出处:网络
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

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 +开发者_Go百科 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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消