# Re: 关于"寻找"功能

Posted by 小琳 on August 18, 1999 at 21:50:48:

In Reply to: 关于"寻找"功能 posted by Steven Sin on August 18, 1999 at 19:45:46:

: 怎样写才可以在 RichTextBox 里有寻找字串的功能?

:::在Form里面放入Richtextbox,Textbox及一个按钮，执行这个
程式时，在TextBox里面键入搜寻的字串，然后按下Enter键
，按钮的目的是假如有二个以上符合的话，可以使用向下
来搜寻，程式如下：
Option Explicit
Dim temp As Integer

Private Sub Command1_Click()
temp = temp + 1
temp = InStr(temp, RichTextBox1.Text, Trim(Text1.Text))
If temp = 0 Then
MsgBox "没有找到"
Else
MsgBox "有找到"
RichTextBox1.SetFocus
RichTextBox1.SelStart = temp - 1
RichTextBox1.SelLength = 1
End If
End Sub

Private Sub Form_Load()
temp = 1
Command1.Enabled = False
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
temp = InStr(temp, RichTextBox1.Text, Trim(Text1.Text))
If temp = 0 Then
MsgBox "没有找到"
Else
MsgBox "有找到"
Command1.Enabled = True
RichTextBox1.SetFocus
RichTextBox1.SelStart = temp - 1
RichTextBox1.SelLength = 1
End If
End If
End Sub

Follow Ups: