📄 findform.vb
字号:
Public Class FindForm
Inherits System.Windows.Forms.Form
Dim i = 1, k As Integer
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
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
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents BtFind As System.Windows.Forms.Button
Friend WithEvents BtCancel As System.Windows.Forms.Button
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
Friend WithEvents TxtFind As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FindForm))
Me.Label1 = New System.Windows.Forms.Label
Me.BtFind = New System.Windows.Forms.Button
Me.BtCancel = New System.Windows.Forms.Button
Me.CheckBox1 = New System.Windows.Forms.CheckBox
Me.RadioButton1 = New System.Windows.Forms.RadioButton
Me.RadioButton2 = New System.Windows.Forms.RadioButton
Me.TxtFind = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 16)
Me.Label1.TabIndex = 0
Me.Label1.Text = "查找内容(&N)"
'
'BtFind
'
Me.BtFind.Enabled = False
Me.BtFind.Location = New System.Drawing.Point(256, 8)
Me.BtFind.Name = "BtFind"
Me.BtFind.Size = New System.Drawing.Size(96, 23)
Me.BtFind.TabIndex = 1
Me.BtFind.Text = "查找下一个(&F)"
'
'BtCancel
'
Me.BtCancel.Location = New System.Drawing.Point(256, 40)
Me.BtCancel.Name = "BtCancel"
Me.BtCancel.Size = New System.Drawing.Size(96, 23)
Me.BtCancel.TabIndex = 2
Me.BtCancel.Text = "取消"
'
'CheckBox1
'
Me.CheckBox1.Location = New System.Drawing.Point(8, 96)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(120, 24)
Me.CheckBox1.TabIndex = 3
Me.CheckBox1.Text = "区分大小写(&C)"
'
'RadioButton1
'
Me.RadioButton1.Location = New System.Drawing.Point(128, 96)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.TabIndex = 4
Me.RadioButton1.Text = "向上(&U)"
'
'RadioButton2
'
Me.RadioButton2.Location = New System.Drawing.Point(248, 88)
Me.RadioButton2.Name = "RadioButton2"
Me.RadioButton2.Size = New System.Drawing.Size(104, 32)
Me.RadioButton2.TabIndex = 5
Me.RadioButton2.Text = "向下(&D)"
'
'TxtFind
'
Me.TxtFind.Location = New System.Drawing.Point(120, 8)
Me.TxtFind.Name = "TxtFind"
Me.TxtFind.Size = New System.Drawing.Size(136, 21)
Me.TxtFind.TabIndex = 6
Me.TxtFind.Text = ""
'
'FindForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(360, 126)
Me.Controls.Add(Me.TxtFind)
Me.Controls.Add(Me.RadioButton2)
Me.Controls.Add(Me.RadioButton1)
Me.Controls.Add(Me.CheckBox1)
Me.Controls.Add(Me.BtCancel)
Me.Controls.Add(Me.BtFind)
Me.Controls.Add(Me.Label1)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "FindForm"
Me.Text = "查找"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub TxtFind_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtFind.TextChanged
If Trim(TxtFind.Text) = "" Then
BtFind.Enabled = False
Else
BtFind.Enabled = True
End If
End Sub
Private Sub find()
i += k
If k = 0 Then
MsgBox("没有找到" & TxtFind.Text)
i = 1
Exit Sub
End If
ob_form.RTextBox.SelectionStart() = i - 2
ob_form.RTextBox.SelectionLength() = Len(TxtFind.Text)
ob_form.Focus()
End Sub
Private Sub find2()
i -= k
If k = 0 Then
MsgBox("没有找到" & TxtFind.Text)
i = Len(ob_form.RTextBox.Text)
Exit Sub
End If
ob_form.RTextBox.SelectionStart() = i - Len(TxtFind.Text)
ob_form.RTextBox.SelectionLength() = Len(TxtFind.Text)
End Sub
Private Sub BtFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtFind.Click
If CheckBox1.Checked = True Then
If RadioButton2.Checked = True Then
k = InStr(Mid(ob_form.RTextBox.Text, i), TxtFind.Text, CompareMethod.Binary)
Me.find()
Else
Dim str As String = StrReverse(Microsoft.VisualBasic.Left(ob_form.RTextBox.Text, i))
k = InStr(str, StrReverse(TxtFind.Text), CompareMethod.Binary)
Me.find2()
End If
Else
If RadioButton2.Checked = True Then
k = InStr(Mid(ob_form.RTextBox.Text, i), TxtFind.Text, CompareMethod.Text)
Me.find()
Else
Dim str As String = StrReverse(Microsoft.VisualBasic.Left(ob_form.RTextBox.Text, i))
k = InStr(str, StrReverse(TxtFind.Text), CompareMethod.Text)
Me.find2()
End If
End If
End Sub
Private Sub BtCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtCancel.Click
Me.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -