如何打字程序一样,在文本框中输入字,对是一种颜色,错是另一种颜色!

loverain520 2005-03-22 05:03:57
本人正在编写一个程序,不知这一种方法如何写啊!
“如何打字程序一样,在文本框中输入字,对是一种颜色,错是另一种颜色!”
请高手指点。
...全文
96 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lyj0558 2005-03-22
  • 打赏
  • 举报
回复
我给你写了一段,很简单的一段,只适合一个字一个字的输入,并且只可以在接尾输入,真正达到像打字的那样,还得靠你自己了:
Private Sub RichTextBox1_Change()
If Right(RichTextBox1.Text, 1) = "对" Then
RichTextBox1.SelStart = Len(RichTextBox1.Text) - 1
RichTextBox1.SelLength = 1
RichTextBox1.SelColor = vbGreen
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelLength = 0
ElseIf Right(RichTextBox1.Text, 1) = "错" Then
RichTextBox1.SelStart = Len(RichTextBox1.Text) - 1
RichTextBox1.SelLength = 1
RichTextBox1.SelColor = vbRed
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelLength = 0
Else
RichTextBox1.SelStart = Len(RichTextBox1.Text) - 1
RichTextBox1.SelLength = 1
RichTextBox1.SelColor = vbBlack
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelLength = 0
End If

End Sub
Gutta 2005-03-22
  • 打赏
  • 举报
回复
思路可以这样:
首先建立一份参照的字符串,譬如:
I am a boy.
然后在RichTextbox中输入的时候,就开始逐个进行判断,如果出错,则改变颜色
利用SelStart和SelLength还有SelColor函数。

具体用法查MSDN和网上的资料文章。
pcwak 2005-03-22
  • 打赏
  • 举报
回复
请看RichTextBox的用法

7,785

社区成员

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

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