设置不同的颜色在多行TextBox的每一行 [英] Setting different color for each line in multiline TEXTBOX

查看:385
本文介绍了设置不同的颜色在多行TextBox的每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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

使用上述code到所有名称中添加从数据表中使用Environment.NewLine文本框。 这将在TEXTBOX.Now 所有名字,我想不同的颜色替代名称。

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.

我用:

tx_control2.ForeColor = Color.Maroon

不过,上述方案更改的所有名称的颜色。

But above solution change the color of all names.

我在寻找解决方案。

感谢。

推荐答案

这是不可能用一个文本框。你必须使用一个RichTextBox为。

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

这篇关于设置不同的颜色在多行TextBox的每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆