-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfrmFindandReplace.VB
60 lines (39 loc) · 1.78 KB
/
frmFindandReplace.VB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Public Class frmFindandReplace
Dim txtClientArea As TextBox
Private Sub frmFindandReplace_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Show()
TextBoxSearch.Focus()
End Sub
Private Sub replaceButton_Click(sender As Object, e As EventArgs) Handles replaceButton.Click
Try
Dim replacetext As String = txtClientArea.Text
If txtClientArea.SelectedText.Length <= 0 Then
Dim s As String = txtClientArea.SelectedText
Dim nextPos As Integer
nextPos = txtClientArea.Text.IndexOf(txtClientArea.SelectedText)
While ((nextPos < txtClientArea.Text.Length) And (nextPos >= 0))
txtClientArea.SelectionStart = nextPos
txtClientArea.SelectionLength = s.Length
txtClientArea.Text = txtClientArea.Text.Replace(s, replacetext)
nextPos = txtClientArea.Text.IndexOf(s, nextPos + 1)
End While
End If
Catch ex As Exception
MessageBox.Show(String.Concat("An error occurred: ", ex.Message))
End Try
End Sub
Private Sub findButton_Click(sender As Object, e As EventArgs) Handles findButton.Click
Dim searchString As String
Dim findPos As Integer
Try
searchString = TextBoxSearch.Text
findPos = InStr(searchString, txtClientArea.Text)
If findPos > 0 Then txtClientArea.Focus()
txtClientArea.SelectionStart = findPos - 1
txtClientArea.SelectionLength = searchString.Length
txtClientArea.ScrollToCaret()
Catch ex As Exception
MessageBox.Show(String.Concat("An error occurred: ", ex.Message))
End Try
End Sub
End Class