LLAMAR AL FORMULARIO
Private Sub SubIndiceButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubIndiceButton2.Click
frmReplace.Show()
End Sub
Private Sub btnbuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbuscar.Click
Dim StartPosition As Integer
Dim SearchType As CompareMethod
StartPosition = InStr(1, Form1.RichTextBox1.Text, txtbuscar.Text, SearchType)
If StartPosition = 0 Then
MessageBox.Show("Palabra: '" & txtbuscar.Text.ToString() & "'No encontrada", "Búsqueda en el documento", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Exit Sub
End If
form1.richtextbox1.Select(StartPosition - 1, txtbuscar.Text.Length)
form1.richtextbox1.ScrollToCaret()
Form1.Focus()
End Sub
Private Sub btnbuscarsiguiente_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbuscarsig.Click
Dim StartPosition As Integer = form1.richtextbox1.SelectionStart + 2
Dim SearchType As CompareMethod
StartPosition = InStr(StartPosition, Form1.RichTextBox1.Text, txtbuscar.Text, SearchType)
If StartPosition = 0 Then
MessageBox.Show("Palabra: '" & txtbuscar.Text.ToString() & "' No encontrada", "Búsqueda en el documento", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Exit Sub
End If
Form1.RichTextBox1.Select(StartPosition - 1, txtbuscar.Text.Length)
Form1.RichTextBox1.ScrollToCaret()
Form1.Focus()
End Sub
Private Sub btnReemplazar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReemplazar.Click
If form1.richtextbox1.SelectedText.Length <> 0 Then
form1.richtextbox1.SelectedText = txtreemplazar.Text
End If
Dim StartPosition As Integer = form1.richtextbox1.SelectionStart + 2
Dim SearchType As CompareMethod
StartPosition = InStr(StartPosition, Form1.RichTextBox1.Text, txtbuscar.Text, SearchType)
If StartPosition = 0 Then
MessageBox.Show("Palabra: '" & txtbuscar.Text.ToString() & "' No encontrada", "Búsqueda en el documento", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Exit Sub
End If
form1.richtextbox1.Select(StartPosition - 1, txtbuscar.Text.Length)
form1.richtextbox1.ScrollToCaret()
Form1.Focus()
End Sub
Private Sub btnReemplazartodo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReemplazartodo.Click
Dim currentPosition As Integer = form1.richtextbox1.SelectionStart
Dim currentSelect As Integer = form1.richtextbox1.SelectionLength
form1.richtextbox1.Rtf = Replace(form1.richtextbox1.Rtf, Trim(txtbuscar.Text), Trim(txtreemplazar.Text))
form1.richtextbox1.SelectionStart = currentPosition
form1.richtextbox1.SelectionLength = currentSelect
Form1.Focus()
End Sub