主题:[讨论]查找替换功能探讨
Public Class Form2
Inherits System.Windows.Forms.Form
Dim pos As Integer
Dim tpos As Integer = 1
Dim num As Integer
Dim form3 As New form3
End Sub
Private Sub findtext(ByVal start As Integer) '查找
Dim text2 As String
text2 = TextBox1.Text
pos = InStr(start, form3.RichTextBox1.Text, text2)
If pos > 0 Then
tpos = pos
form3.RichTextBox1.SelectionStart = tpos - 1
form3.RichTextBox1.SelectionLength = Microsoft.VisualBasic.Len(text2)
form3.RichTextBox1.Focus()
Else
MsgBox("查找完毕!" & "共找到" & num & "个!")
'TextBox1.Focus()
End If
End Sub
Private Sub findtext1(ByVal start As Integer) '替换
Dim text2, text3 As String
text2 = TextBox1.Text
text3 = TextBox2.Text
pos = InStr(start, form3.RichTextBox1.Text, text2)
If pos > 0 Then
tpos = pos
form3.RichTextBox1.SelectionStart = tpos - 1
form3.RichTextBox1.SelectionLength = Microsoft.VisualBasic.Len(text2)
form3.RichTextBox1.Focus()
form3.RichTextBox1.SelectedText = text3
Else
MsgBox("替换完毕!" & "共替换" & num & "个!")
'TextBox1.Focus()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '查找按钮
findtext(1)
If pos > 0 Then
num = 1
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click '查找下一个按钮
findtext(tpos + Len(TextBox1.Text))
num += 1
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
num = 0
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'替换按钮
findtext(1)
findtext1(tpos)
num += 1
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
num = 0
End Sub
如果被查询的窗口只有一个则行的通,
但如果象多文档编辑器有很多个文档该如何确定要查找的是哪个文档?
Inherits System.Windows.Forms.Form
Dim pos As Integer
Dim tpos As Integer = 1
Dim num As Integer
Dim form3 As New form3
End Sub
Private Sub findtext(ByVal start As Integer) '查找
Dim text2 As String
text2 = TextBox1.Text
pos = InStr(start, form3.RichTextBox1.Text, text2)
If pos > 0 Then
tpos = pos
form3.RichTextBox1.SelectionStart = tpos - 1
form3.RichTextBox1.SelectionLength = Microsoft.VisualBasic.Len(text2)
form3.RichTextBox1.Focus()
Else
MsgBox("查找完毕!" & "共找到" & num & "个!")
'TextBox1.Focus()
End If
End Sub
Private Sub findtext1(ByVal start As Integer) '替换
Dim text2, text3 As String
text2 = TextBox1.Text
text3 = TextBox2.Text
pos = InStr(start, form3.RichTextBox1.Text, text2)
If pos > 0 Then
tpos = pos
form3.RichTextBox1.SelectionStart = tpos - 1
form3.RichTextBox1.SelectionLength = Microsoft.VisualBasic.Len(text2)
form3.RichTextBox1.Focus()
form3.RichTextBox1.SelectedText = text3
Else
MsgBox("替换完毕!" & "共替换" & num & "个!")
'TextBox1.Focus()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '查找按钮
findtext(1)
If pos > 0 Then
num = 1
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click '查找下一个按钮
findtext(tpos + Len(TextBox1.Text))
num += 1
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
num = 0
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'替换按钮
findtext(1)
findtext1(tpos)
num += 1
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
num = 0
End Sub
如果被查询的窗口只有一个则行的通,
但如果象多文档编辑器有很多个文档该如何确定要查找的是哪个文档?