RichTextBoxFinds is the thing to try for RichTextBoxes.
See note in code below to change the 'replace all' sub.
Sorry it is not more specific, but it can be used as an add
on form to a solution that uses a RichTextBox.
PublicClass FindForm
Inherits System.Windows.Forms.Form
#Region" Windows Form Designer generated code "
PublicSubNew()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
EndSub
'Form overrides dispose to clean up the component list.
ProtectedOverloadsOverridesSub Dispose(ByVal disposingAsBoolean)
If disposingThen
IfNot (componentsIsNothing)Then
components.Dispose()
EndIf
EndIf
MyBase.Dispose(disposing)
EndSub
FriendWithEvents bttnFindAs System.Windows.Forms.Button
FriendWithEvents bttnFindNextAs System.Windows.Forms.Button
FriendWithEvents bttnReplaceAs System.Windows.Forms.Button
FriendWithEvents bttnReplaceAllAs System.Windows.Forms.Button
FriendWithEvents txtSearchWordAs System.Windows.Forms.TextBox
FriendWithEvents txtReplaceWordAs System.Windows.Forms.TextBox
FriendWithEvents chkCaseAs System.Windows.Forms.CheckBox
FriendWithEvents chkWordAs System.Windows.Forms.CheckBox
'Required by the Windows Form Designer
Private componentsAs System.ComponentModel.Container
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()>PrivateSub InitializeComponent()
Me.bttnReplace =New System.Windows.Forms.Button
Me.bttnFindNext =New System.Windows.Forms.Button
Me.chkWord =New System.Windows.Forms.CheckBox
Me.bttnFind =New System.Windows.Forms.Button
Me.txtSearchWord =New System.Windows.Forms.TextBox
Me.txtReplaceWord =New System.Windows.Forms.TextBox
Me.chkCase =New System.Windows.Forms.CheckBox
Me.bttnReplaceAll =New System.Windows.Forms.Button
Me.SuspendLayout()
'
'bttnReplace
'
Me.bttnReplace.Font =New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,CType(0,Byte))
Me.bttnReplace.Location =New System.Drawing.Point(224, 40)
Me.bttnReplace.Name ="bttnReplace"
Me.bttnReplace.Size =New System.Drawing.Size(96, 23)
Me.bttnReplace.TabIndex = 4
Me.bttnReplace.Text ="Replace"
'
'bttnFindNext
'
Me.bttnFindNext.Font =New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,CType(0,Byte))
Me.bttnFindNext.Location =New System.Drawing.Point(336, 8)
Me.bttnFindNext.Name ="bttnFindNext"
Me.bttnFindNext.Size =New System.Drawing.Size(96, 23)
Me.bttnFindNext.TabIndex = 3
Me.bttnFindNext.Text ="Find Next"
'
'chkWord
'
Me.chkWord.Font =New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,CType(0,Byte))
Me.chkWord.Location =New System.Drawing.Point(8, 96)
Me.chkWord.Name ="chkWord"
Me.chkWord.Size =New System.Drawing.Size(152, 24)
Me.chkWord.TabIndex = 7
Me.chkWord.Text ="Whole Word Only"
'
'bttnFind
'
Me.bttnFind.Font =New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,CType(0,Byte))
Me.bttnFind.Location =New System.Drawing.Point(224, 8)
Me.bttnFind.Name ="bttnFind"
Me.bttnFind.Size =New System.Drawing.Size(96, 23)
Me.bttnFind.TabIndex = 2
Me.bttnFind.Text ="Find"
'
'txtSearchWord
'
Me.txtSearchWord.Font =New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,CType(0,Byte))
Me.txtSearchWord.Location =New System.Drawing.Point(8, 8)
Me.txtSearchWord.Name ="txtSearchWord"
Me.txtSearchWord.Size =New System.Drawing.Size(200, 22)
Me.txtSearchWord.TabIndex = 0
Me.txtSearchWord.Text =""
'
'txtReplaceWord
'
Me.txtReplaceWord.Font =New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,CType(0,Byte))
Me.txtReplaceWord.Location =New System.Drawing.Point(8, 40)
Me.txtReplaceWord.Name ="txtReplaceWord"
Me.txtReplaceWord.Size =New System.Drawing.Size(200, 22)
Me.txtReplaceWord.TabIndex = 1
Me.txtReplaceWord.Text =""
'
'chkCase
'
Me.chkCase.Font =New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,CType(0,Byte))
Me.chkCase.Location =New System.Drawing.Point(8, 72)
Me.chkCase.Name ="chkCase"
Me.chkCase.Size =New System.Drawing.Size(152, 24)
Me.chkCase.TabIndex = 6
Me.chkCase.Text ="Case Sensitive"
'
'bttnReplaceAll
'
Me.bttnReplaceAll.Font =New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,CType(0,Byte))
Me.bttnReplaceAll.Location =New System.Drawing.Point(336, 40)
Me.bttnReplaceAll.Name ="bttnReplaceAll"
Me.bttnReplaceAll.Size =New System.Drawing.Size(96, 23)
Me.bttnReplaceAll.TabIndex = 5
Me.bttnReplaceAll.Text ="Replace All"
'
'FindForm
'
Me.AutoScaleBaseSize =New System.Drawing.Size(5, 13)
Me.ClientSize =New System.Drawing.Size(440, 125)
Me.Controls.Add(Me.chkWord)
Me.Controls.Add(Me.chkCase)
Me.Controls.Add(Me.bttnReplaceAll)
Me.Controls.Add(Me.bttnReplace)
Me.Controls.Add(Me.bttnFindNext)
Me.Controls.Add(Me.bttnFind)
Me.Controls.Add(Me.txtReplaceWord)
Me.Controls.Add(Me.txtSearchWord)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox =False
Me.Name ="FindForm"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text ="Search and Replace"
Me.TopMost =True
Me.ResumeLayout(False)
EndSub
#EndRegion
' Dim RTFForm As Form
PrivateSub txtSearchWord_TextChanged(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles txtSearchWord.TextChanged, txtReplaceWord.TextChanged
found =False
If txtSearchWord.Text.Length > 0Then
bttnFind.Enabled =True
bttnFindNext.Enabled =True
If txtReplaceWord.Text.Length > 0Then
If foundThen
bttnReplace.Enabled =True
Else
bttnReplace.Enabled =False
EndIf
bttnReplaceAll.Enabled =True
Else
bttnReplace.Enabled =False
bttnReplaceAll.Enabled =False
EndIf
Else
bttnFind.Enabled =False
bttnFindNext.Enabled =False
bttnReplace.Enabled =False
bttnReplaceAll.Enabled =False
EndIf
EndSub
Public wordAtAsInteger
Public foundAsBoolean =False
PrivateSub bttnFind_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles bttnFind.Click, bttnFindNext.Click
If senderIs bttnFindThen
wordAt = 0
Else
wordAt += 1
EndIf
Dim srchModeAs RichTextBoxFinds
srchMode = SetSearchMode()
wordAt = Form1.RichTextBox1.Find(txtSearchWord.Text, wordAt, srchMode)
If wordAt = -1Then
MsgBox("Can't find any (more) matches", ,"Find and Replace")
found =False
ExitSub
EndIf
Form1.RichTextBox1.Select(wordAt, txtSearchWord.Text.Length)
Form1.RichTextBox1.ScrollToCaret()
found =True
If txtReplaceWord.Text.Length > 0Then
bttnReplace.Enabled =True
EndIf
EndSub
PrivateSub bttnReplaceAll_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles bttnReplaceAll.Click
Dim countAsInteger = 0
Dim srchModeAs RichTextBoxFinds
srchMode = SetSearchMode()
wordAt = 0
DoWhile wordAt <> -1
wordAt = Form1.RichTextBox1.Find(txtSearchWord.Text, wordAt, srchMode)
If wordAt = -1Then
Form1.RichTextBox1.ScrollToCaret()
MsgBox(count.ToString &" Replacements made", ,"Find and Replace")
ExitDo
Else
Form1.RichTextBox1.Select(wordAt, txtSearchWord.Text.Length)
' COMMENT OUT THE LINE BELOW TO GET JUST A COUNT
Form1.RichTextBox1.SelectedText = txtReplaceWord.Text
If txtSearchWord.Text.Length < txtReplaceWord.Text.LengthThen
wordAt = wordAt + txtSearchWord.Text.Length
Else
wordAt = wordAt + txtReplaceWord.Text.Length
EndIf
count += 1
EndIf
Loop
bttnFindNext.Enabled =False
bttnReplace.Enabled =False
bttnReplaceAll.Enabled =False
EndSub
PrivateSub bttnReplace_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles bttnReplace.Click
If Form1.RichTextBox1.SelectedText <>""Then
Form1.RichTextBox1.SelectedText = txtReplaceWord.Text
EndIf
bttnFind_Click(sender, e)
EndSub
Function SetSearchMode()As RichTextBoxFinds
Dim modeAs RichTextBoxFinds
If chkCase.Checked =TrueThen
mode = RichTextBoxFinds.MatchCase
Else
mode = RichTextBoxFinds.None
EndIf
If chkWord.Checked =TrueThen
mode = modeOr RichTextBoxFinds.WholeWord
Else
mode = modeOr RichTextBoxFinds.None
EndIf
SetSearchMode = mode
EndFunction
PrivateSub FindForm_FormClosing(ByVal senderAsObject,ByVal eAs System.Windows.Forms.FormClosingEventArgs)HandlesMe.FormClosing
found =False
EndSub
PrivateSub FindForm_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load
If txtSearchWord.Text.Length > 0Then
bttnFind.Enabled =True
bttnFindNext.Enabled =True
If txtReplaceWord.Text.Length > 0Then
If foundThen
bttnReplace.Enabled =True
Else
bttnReplace.Enabled =False
EndIf
bttnReplaceAll.Enabled =True
Else
bttnReplace.Enabled =False
bttnReplaceAll.Enabled =False
EndIf
Else
bttnFind.Enabled =False
bttnFindNext.Enabled =False
bttnReplace.Enabled =False
bttnReplaceAll.Enabled =False
EndIf
EndSub
EndClass