Public I As Integer '找到字符串的位置
Public Count As Integer = 1 '是否是第一次查找
Public Direction As Integer = 2 '搜索方向
Public UWrite As Boolean
Public Source As String
Dim J As Integer '下一次查找的其始位置
Dim Length As String = Len(TxtStr.Text) '被找字符串的长度
If UWrite = False Then '*****************************
Source = UCase(FrmNote.Just.TxtBody.Text) '*
Find = UCase(TxtStr.Text) '*
Else '*判断是否按照大小写查找
Source = FrmNote.Just.TxtBody.Text '*
Find = TxtStr.Text '*
End If '******************************
If FrmNote.Just.TxtBody.SelectionStart = 0 Then '判断当前光标是否在最前面位置
MessageBox.Show("已经到达最前位置", "记事本", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Else
If Count = 1 Then '判断是否是第一次查找
I = Source.LastIndexOf(Find, FrmNote.Just.TxtBody.SelectionStart) '查找是否有匹配的字符
If Not (I = -1) Then '如果找到所要查找的字符
FrmNote.Just.TxtBody.Select(I, Length)
Count += 1
Else
MessageBox.Show("找不到[" & TxtStr.Text & "]", "记事本", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
End If
Else '继续查找
J = I - 2 + Length
I = Source.LastIndexOf(Find, J)
If Not (I = -1) Then
FrmNote.Just.TxtBody.Select(I, Length)
Else
MessageBox.Show("找不到[" & TxtStr.Text & "]", "记事本", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
End If
End If
End If
FrmNote.Just.TxtBody.ScrollToCaret()
[此贴子已经被作者于2006-12-21 8:12:32编辑过]