怎样让特定的字符串显示特定的颜色?

duguduggu 2003-03-24 08:17:25
我想让特定的字符串在文本框中显示特定的颜色,有什么方法吗?
...全文
214 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
northwolves 2003-03-25
  • 打赏
  • 举报
回复

Private Sub Command1_Click()

Dim str As String

Dim Text As String

Dim Position As Integer

Dim Lenth As Integer

Text = InputBox("特定的字符串")

If Text <> "" Then

Position = InStr(RichTextBox1.Text, Text) - 1

Lenth = Len(Text)

RichTextBox1.SelStart = Position

RichTextBox1.SelLength = Lenth

RichTextBox1.SelColor = RGB(255, 0, 0)

Do While InStr(Position + Lenth + 1, RichTextBox1.Text, Text) <> 0

Position = InStr(Position + Lenth + 1, RichTextBox1.Text, Text) - 1

RichTextBox1.SelStart = Position

RichTextBox1.SelLength = Lenth

RichTextBox1.SelColor = RGB(255, 0, 0)

Loop

End If

End Sub
lihonggen0 2003-03-25
  • 打赏
  • 举报
回复
richtextbox
Wang_xiaoni 2003-03-24
  • 打赏
  • 举报
回复
建立一个要特别显示的字符串的总字符串,每个字符串中间用空格格开,用一个循环检测richtextbox中的字在总字符串中的INSTR值是否为0 ,不为0即显示,这样做你可以建立许多要特别显示的字符串
落伍者 2003-03-24
  • 打赏
  • 举报
回复

在文本框只能用一中前景色,如果要想在在同一个框中的文字颜色不同.
要用richtextbox.



lxcc 2003-03-24
  • 打赏
  • 举报
回复
select YourString
case "特定一"
text1.forecolor=vbred
case "特定二"
text1.forecolor=vbblue
...
end select
zqsntws 2003-03-24
  • 打赏
  • 举报
回复
你可以给特定的文本框设置特定的颜色!

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧