📄 findform.vb
字号:
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 txtSearchWord As System.Windows.Forms.TextBox
Friend WithEvents txtReplaceWord As System.Windows.Forms.TextBox
Friend WithEvents chkCase As System.Windows.Forms.CheckBox
Friend WithEvents chkWord 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.
<System.Diagnostics.DebuggerStepThrough()> Private Sub 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.AddRange(New System.Windows.Forms.Control() {Me.chkWord, Me.chkCase, Me.bttnReplaceAll, Me.bttnReplace, Me.bttnFindNext, Me.bttnFind, Me.txtReplaceWord, Me.txtSearchWord})
Me.Name = "FindForm"
Me.Text = "Search & Replace"
Me.TopMost = True
Me.ResumeLayout(False)
End Sub
#End Region
Dim RTFForm As Form
Private Sub txtSearchWord_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearchWord.TextChanged
If txtSearchWord.Text.Length > 0 Then
bttnFind.Enabled = True
bttnFindNext.Enabled = True
Else
bttnFind.Enabled = False
bttnFindNext.Enabled = False
End If
If txtReplaceWord.Text.Length > 0 Then
bttnReplace.Enabled = True
bttnReplaceAll.Enabled = True
Else
bttnReplace.Enabled = False
bttnReplaceAll.Enabled = False
End If
End Sub
Private Sub bttnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnFind.Click
Dim wordAt As Integer
Dim srchMode As RichTextBoxFinds
srchMode = SetSearchMode()
wordAt = EditorForm.RTFBox.Find(txtSearchWord.Text, 0, srchMode)
If wordAt = -1 Then
MsgBox("Can't find word")
Exit Sub
End If
EditorForm.RTFBox.Select(wordAt, txtSearchWord.Text.Length)
bttnFindNext.Enabled = True
bttnReplace.Enabled = True
bttnReplaceAll.Enabled = True
EditorForm.RTFBox.ScrollToCaret()
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 CompareMethod
srchMode = SetSearchMode()
selStart = InStr(EditorForm.RTFBox.SelectionStart + 2, EditorForm.RTFBox.Text, txtSearchWord.Text, srchMode)
If selStart = 0 Then
MsgBox("No more matches")
Exit Sub
End If
EditorForm.RTFBox.Select(selStart - 1, txtSearchWord.Text.Length)
EditorForm.RTFBox.ScrollToCaret()
End Sub
Private Sub bttnReplaceAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnReplaceAll.Click
Dim curPos, curSel As Integer
curPos = EditorForm.RTFBox.SelectionStart
curSel = EditorForm.RTFBox.SelectionLength
EditorForm.RTFBox.Text = Replace(EditorForm.RTFBox.Text, Trim(txtSearchWord.Text), Trim(txtReplaceWord.Text))
EditorForm.RTFBox.SelectionStart = curPos
EditorForm.RTFBox.SelectionLength = curSel
End Sub
Private Sub bttnReplace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnReplace.Click
If EditorForm.RTFBox.SelectedText <> "" Then
EditorForm.RTFBox.SelectedText = txtReplaceWord.Text
End If
bttnFindNext_Click(sender, e)
End Sub
Function SetSearchMode() As RichTextBoxFinds
Dim mode As RichTextBoxFinds
If chkCase.Checked = True Then
mode = RichTextBoxFinds.MatchCase
Else
mode = RichTextBoxFinds.None
End If
If chkWord.Checked = True Then
mode = mode Or RichTextBoxFinds.WholeWord
Else
mode = mode Or RichTextBoxFinds.None
End If
SetSearchMode = mode
End Function
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -