Public Class FindForm Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Friend WithEvents bttnFind As System.Windows.Forms.Button Friend WithEvents bttnFindNext As System.Windows.Forms.Button Friend WithEvents bttnReplace As System.Windows.Forms.Button Friend WithEvents bttnReplaceAll As System.Windows.Forms.Button Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents searchWord As System.Windows.Forms.TextBox Friend WithEvents replaceWord As System.Windows.Forms.TextBox Friend WithEvents chkCase As System.Windows.Forms.CheckBox 'Required by the Windows Form Designer Private components As 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. Private Sub InitializeComponent() Me.bttnReplace = New System.Windows.Forms.Button() Me.Label1 = New System.Windows.Forms.Label() Me.Label2 = New System.Windows.Forms.Label() Me.bttnFindNext = New System.Windows.Forms.Button() Me.bttnFind = New System.Windows.Forms.Button() Me.chkCase = New System.Windows.Forms.CheckBox() Me.bttnReplaceAll = New System.Windows.Forms.Button() Me.searchWord = New System.Windows.Forms.TextBox() Me.replaceWord = New System.Windows.Forms.TextBox() Me.SuspendLayout() ' 'bttnReplace ' Me.bttnReplace.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.bttnReplace.Location = New System.Drawing.Point(256, 64) Me.bttnReplace.Name = "bttnReplace" Me.bttnReplace.Size = New System.Drawing.Size(96, 32) Me.bttnReplace.TabIndex = 7 Me.bttnReplace.Text = "Replace" ' 'Label1 ' Me.Label1.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.Label1.Location = New System.Drawing.Point(8, 0) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(184, 16) Me.Label1.TabIndex = 0 Me.Label1.Text = "Search For" ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.Label2.Location = New System.Drawing.Point(8, 48) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(184, 16) Me.Label2.TabIndex = 2 Me.Label2.Text = "Replace With" ' 'bttnFindNext ' Me.bttnFindNext.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.bttnFindNext.Location = New System.Drawing.Point(360, 16) Me.bttnFindNext.Name = "bttnFindNext" Me.bttnFindNext.Size = New System.Drawing.Size(96, 32) Me.bttnFindNext.TabIndex = 6 Me.bttnFindNext.Text = "Find Next" ' 'bttnFind ' Me.bttnFind.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.bttnFind.Location = New System.Drawing.Point(256, 16) Me.bttnFind.Name = "bttnFind" Me.bttnFind.Size = New System.Drawing.Size(96, 32) Me.bttnFind.TabIndex = 5 Me.bttnFind.Text = "Find" ' 'chkCase ' Me.chkCase.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.chkCase.Location = New System.Drawing.Point(8, 96) Me.chkCase.Name = "chkCase" Me.chkCase.Size = New System.Drawing.Size(160, 16) Me.chkCase.TabIndex = 4 Me.chkCase.Text = "Case Sensitive" ' 'bttnReplaceAll ' Me.bttnReplaceAll.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.bttnReplaceAll.Location = New System.Drawing.Point(360, 64) Me.bttnReplaceAll.Name = "bttnReplaceAll" Me.bttnReplaceAll.Size = New System.Drawing.Size(96, 32) Me.bttnReplaceAll.TabIndex = 8 Me.bttnReplaceAll.Text = "Replace All" ' 'searchWord ' Me.searchWord.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.searchWord.Location = New System.Drawing.Point(8, 24) Me.searchWord.Name = "searchWord" Me.searchWord.Size = New System.Drawing.Size(240, 22) Me.searchWord.TabIndex = 1 Me.searchWord.Text = "" ' 'replaceWord ' Me.replaceWord.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.replaceWord.Location = New System.Drawing.Point(8, 72) Me.replaceWord.Name = "replaceWord" Me.replaceWord.Size = New System.Drawing.Size(240, 22) Me.replaceWord.TabIndex = 3 Me.replaceWord.Text = "" ' 'FindForm ' Me.AcceptButton = Me.bttnFind Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(464, 117) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label2, Me.Label1, Me.replaceWord, Me.chkCase, Me.bttnReplaceAll, Me.bttnReplace, Me.bttnFindNext, Me.bttnFind, Me.searchWord}) Me.Name = "FindForm" Me.Text = "Find & Replace" Me.TopMost = True Me.ResumeLayout(False) End Sub #End Region Private Sub bttnReplaceAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnReplaceAll.Click Dim curPos, curSel As Integer curPos = TXTPADForm.txtBox.SelectionStart curSel = TXTPADForm.txtBox.SelectionLength TXTPADForm.txtBox.Text = Replace(TXTPADForm.txtBox.Text, Trim(searchWord.Text), Trim(replaceWord.Text)) TXTPADForm.txtBox.SelectionStart = curPos TXTPADForm.txtBox.SelectionLength = curSel End Sub Private Sub bttnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnFind.Click Dim selStart As Integer Dim srchMode As Microsoft.VisualBasic.CompareMethod If chkCase.Checked = True Then srchMode = CompareMethod.Binary Else srchMode = CompareMethod.Text End If selStart = InStr(TXTPADForm.txtBox.Text, searchWord.Text, srchMode) If selStart = 0 Then MsgBox("Can't find word") Exit Sub End If TXTPADForm.txtBox.Select(selStart - 1, searchWord.Text.Length) bttnFindNext.Enabled = True bttnReplace.Enabled = True bttnReplaceAll.Enabled = True TXTPADForm.txtBox.ScrollToCaret() End Sub Private Sub searchWord_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles searchWord.TextChanged If searchWord.Text.Length > 0 Then bttnFind.Enabled = True bttnFindNext.Enabled = True Else bttnFind.Enabled = False bttnFindNext.Enabled = False End If If replaceWord.Text.Length > 0 Then bttnReplace.Enabled = True bttnReplaceAll.Enabled = True Else bttnReplace.Enabled = False bttnReplaceAll.Enabled = False End If End Sub Private Sub bttnFindNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnFindNext.Click Dim selStart As Integer Dim srchMode As Microsoft.VisualBasic.CompareMethod If chkCase.Checked = True Then srchMode = Microsoft.VisualBasic.CompareMethod.Binary Else srchMode = Microsoft.VisualBasic.CompareMethod.Text End If selStart = InStr(TXTPADForm.txtBox.SelectionStart + 2, TXTPADForm.txtBox.Text, searchWord.Text, srchMode) If selStart = 0 Then MsgBox("No more matches") Exit Sub End If TXTPADForm.txtBox.Select(selStart - 1, searchWord.Text.Length) TXTPADForm.txtBox.ScrollToCaret() End Sub Private Sub Form2_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated searchWord_TextChanged(sender, e) End Sub Private Sub bttnReplace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnReplace.Click If TXTPADForm.txtBox.SelectedText <> "" Then TXTPADForm.txtBox.SelectedText = replaceWord.Text End If bttnFindNext_Click(sender, e) End Sub Private Sub replaceWord_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles replaceWord.TextChanged If replaceWord.Text.Length > 0 Then bttnReplace.Enabled = True bttnReplaceAll.Enabled = True Else bttnReplace.Enabled = False bttnReplaceAll.Enabled = False End If End Sub End Class