replaceform.vb

来自「是一个工资的管理系统 利用的是VB.NET和sql2000来完成的」· VB 代码 · 共 210 行

VB
210
字号
Public Class ReplaceForm
    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 Label2 As System.Windows.Forms.Label
    Friend WithEvents TxtFind As System.Windows.Forms.TextBox
    Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
    Friend WithEvents BtFind As System.Windows.Forms.Button
    Friend WithEvents BtReplace As System.Windows.Forms.Button
    Friend WithEvents BtReplaceAll As System.Windows.Forms.Button
    Friend WithEvents BtCancel As System.Windows.Forms.Button
    Friend WithEvents TxtReplace As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(ReplaceForm))
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.TxtReplace = New System.Windows.Forms.TextBox
        Me.TxtFind = New System.Windows.Forms.TextBox
        Me.BtFind = New System.Windows.Forms.Button
        Me.BtReplace = New System.Windows.Forms.Button
        Me.BtReplaceAll = New System.Windows.Forms.Button
        Me.BtCancel = New System.Windows.Forms.Button
        Me.CheckBox1 = New System.Windows.Forms.CheckBox
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(72, 23)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "查找内容(&N)"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 56)
        Me.Label2.Name = "Label2"
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "替换为(&P)"
        '
        'TxtReplace
        '
        Me.TxtReplace.Location = New System.Drawing.Point(104, 56)
        Me.TxtReplace.Name = "TxtReplace"
        Me.TxtReplace.Size = New System.Drawing.Size(112, 21)
        Me.TxtReplace.TabIndex = 2
        Me.TxtReplace.Text = ""
        '
        'TxtFind
        '
        Me.TxtFind.Location = New System.Drawing.Point(104, 16)
        Me.TxtFind.Name = "TxtFind"
        Me.TxtFind.Size = New System.Drawing.Size(112, 21)
        Me.TxtFind.TabIndex = 3
        Me.TxtFind.Text = ""
        '
        'BtFind
        '
        Me.BtFind.Enabled = False
        Me.BtFind.Location = New System.Drawing.Point(240, 16)
        Me.BtFind.Name = "BtFind"
        Me.BtFind.Size = New System.Drawing.Size(96, 23)
        Me.BtFind.TabIndex = 4
        Me.BtFind.Text = "查找下一个(&F)"
        '
        'BtReplace
        '
        Me.BtReplace.Enabled = False
        Me.BtReplace.Location = New System.Drawing.Point(240, 56)
        Me.BtReplace.Name = "BtReplace"
        Me.BtReplace.Size = New System.Drawing.Size(96, 23)
        Me.BtReplace.TabIndex = 5
        Me.BtReplace.Text = "替换(&R)"
        '
        'BtReplaceAll
        '
        Me.BtReplaceAll.Enabled = False
        Me.BtReplaceAll.Location = New System.Drawing.Point(240, 96)
        Me.BtReplaceAll.Name = "BtReplaceAll"
        Me.BtReplaceAll.Size = New System.Drawing.Size(96, 23)
        Me.BtReplaceAll.TabIndex = 6
        Me.BtReplaceAll.Text = "全部替换(&A)"
        '
        'BtCancel
        '
        Me.BtCancel.Location = New System.Drawing.Point(240, 136)
        Me.BtCancel.Name = "BtCancel"
        Me.BtCancel.Size = New System.Drawing.Size(96, 23)
        Me.BtCancel.TabIndex = 7
        Me.BtCancel.Text = "取消"
        '
        'CheckBox1
        '
        Me.CheckBox1.Location = New System.Drawing.Point(24, 112)
        Me.CheckBox1.Name = "CheckBox1"
        Me.CheckBox1.Size = New System.Drawing.Size(120, 24)
        Me.CheckBox1.TabIndex = 8
        Me.CheckBox1.Text = "区分大小写(&C)"
        '
        'ReplaceForm
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(360, 162)
        Me.Controls.Add(Me.CheckBox1)
        Me.Controls.Add(Me.BtCancel)
        Me.Controls.Add(Me.BtReplaceAll)
        Me.Controls.Add(Me.BtReplace)
        Me.Controls.Add(Me.BtFind)
        Me.Controls.Add(Me.TxtFind)
        Me.Controls.Add(Me.TxtReplace)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "ReplaceForm"
        Me.ShowInTaskbar = False
        Me.Text = "替换"
        Me.TopMost = True
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtReplace.TextChanged
        If Trim(TxtFind.Text) = "" Then
            BtFind.Enabled = False
            BtReplace.Enabled = False
            BtReplaceAll.Enabled = False
        Else
            BtFind.Enabled = True
            BtReplace.Enabled = True
            BtReplaceAll.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 BtFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtFind.Click
        If CheckBox1.Checked = True Then
            k = InStr(Mid(ob_form.RTextBox.Text, i), TxtFind.Text, CompareMethod.Binary)
            Me.Find()
        Else
            k = InStr(Mid(ob_form.RTextBox.Text, i), TxtFind.Text, CompareMethod.Text)
            Me.Find()
        End If
    End Sub

    Private Sub BtReplace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtReplace.Click
        If ob_form.RTextBox.SelectionLength > 0 Then
            If CheckBox1.Checked = True Then
                ob_form.RTextBox.Text = Replace(ob_form.RTextBox.Text, ob_form.RTextBox.SelectedText, TxtReplace.Text, 1, 1, CompareMethod.Binary)
            Else
                ob_form.RTextBox.Text = Replace(ob_form.RTextBox.Text, ob_form.RTextBox.SelectedText, TxtReplace.Text, 1, 1, CompareMethod.Binary)
            End If
        End If
        Me.BtFind_Click(sender, e)
    End Sub

    Private Sub BtReplaceAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtReplaceAll.Click
        Me.BtFind_Click(sender, e)
        If ob_form.RTextBox.SelectionLength > 0 Then
            If CheckBox1.Checked = True Then
                ob_form.RTextBox.Text = Replace(ob_form.RTextBox.Text, ob_form.RTextBox.SelectedText, TxtReplace.Text, 1, , CompareMethod.Binary)
            Else
                ob_form.RTextBox.Text = Replace(ob_form.RTextBox.Text, ob_form.RTextBox.SelectedText, TxtReplace.Text, 1, , CompareMethod.Text)
            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 + =
减小字号Ctrl + -
显示快捷键?