⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 findform.frm

📁 文档编程软件,类似WORD的一个编辑工具.
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmFindForm 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "查找"
   ClientHeight    =   2025
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4695
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2025
   ScaleWidth      =   4695
   ShowInTaskbar   =   0   'False
   StartUpPosition =   1  '所有者中心
   Begin VB.CommandButton cmdCancel 
      Cancel          =   -1  'True
      Caption         =   "取消"
      Height          =   375
      Left            =   3240
      TabIndex        =   9
      Top             =   600
      Width           =   1365
   End
   Begin VB.TextBox txtReplace 
      Enabled         =   0   'False
      Height          =   285
      Left            =   960
      TabIndex        =   5
      Top             =   540
      Width           =   2160
   End
   Begin VB.CommandButton cmdFindNext 
      Caption         =   "查找下一个(&F)"
      Enabled         =   0   'False
      Height          =   375
      Left            =   3240
      TabIndex        =   4
      Top             =   120
      Width           =   1365
   End
   Begin VB.CommandButton cmdReplace 
      Caption         =   "替换(&R)"
      Height          =   375
      Left            =   3240
      TabIndex        =   3
      Top             =   1080
      Width           =   1365
   End
   Begin VB.CommandButton cmdReplaceAll 
      Caption         =   "全部替换(&A)"
      Enabled         =   0   'False
      Height          =   375
      Left            =   3240
      TabIndex        =   2
      Top             =   1560
      Width           =   1365
   End
   Begin VB.ComboBox cboSearch 
      Height          =   315
      ItemData        =   "FindForm.frx":0000
      Left            =   960
      List            =   "FindForm.frx":000D
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   870
      Width           =   2145
   End
   Begin VB.TextBox txtFind 
      Height          =   285
      Left            =   960
      TabIndex        =   0
      Top             =   195
      Width           =   2160
   End
   Begin VB.Label lbl1 
      AutoSize        =   -1  'True
      Caption         =   "查找(&N):"
      Height          =   180
      Left            =   75
      TabIndex        =   8
      Top             =   210
      Width           =   720
   End
   Begin VB.Label lblReplace 
      Caption         =   "替换(&P):"
      Enabled         =   0   'False
      Height          =   255
      Left            =   75
      TabIndex        =   7
      Top             =   555
      Width           =   780
   End
   Begin VB.Label lbl3 
      Caption         =   "方向(&D)"
      Height          =   255
      Left            =   75
      TabIndex        =   6
      Top             =   900
      Width           =   780
   End
End
Attribute VB_Name = "frmFindForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'部分代码版权(C) 1995, Microsoft Corporation
Option Explicit

'*************************************************
' 目的:  如果需要查找一个字符窗并且替换它
' 作用:  调用窗体的文字可能会改变。
' 输入:  strFind:    要查找的文字
'        strReplace: 查找到的文字后要的替换文字
'        intStart:   开始的查找点
'        intEnd:     查找范围
' 返回:  True        文字已找到(并替换了)
'        Flase       文字未找到
'*************************************************
Function FindString(strFind As String, strReplace As String, lngStart As Long, lngEnd As Long) As Boolean
    Dim lngPos As Long '位置
    With frmDDWordPadMDI.ActiveForm.rtf
        '定位查找字符串
        lngPos = InStr(lngStart, .Text, strFind, 1)
        If lngPos = 0 Then
            '未找到
            FindString = False
        Else
            '它被找到了,但是超过了结尾区域,我们将做
            If Not ((lngPos + Len(strFind)) > lngEnd) Then
                '在范围之内
                FindString = True
                .SelStart = lngPos - 1
                .SelLength = Len(strFind)
                '如果“替换”值为空,仅仅只查找
                If strReplace <> "" Then '替换它
                    .SelText = strReplace
                End If
            End If
        End If
    End With
End Function


'*************************************************
' 目的:  卸载窗体
'*************************************************
Private Sub cmdCancel_Click()
    Unload Me
End Sub


'*************************************************
' 目的:  调用查找下一个。
'*************************************************
Private Sub cmdFindNext_Click()
    Dim lngLen As Long '结束位置
    Dim lngStart As Long '开始位置
    
    '设置框内的文字的结尾长度
    lngLen = Len(frmDDWordPadMDI.ActiveForm.rtf.Text)
    
    Select Case cboSearch.ListIndex
        Case 0 '搜索全部
            lngStart = 1
        Case 1 '向后搜索
            lngStart = 1
            '设置当前选择的结尾
            lngLen = frmDDWordPadMDI.ActiveForm.rtf.SelStart
            lngLen = lngLen + frmDDWordPadMDI.ActiveForm.rtf.SelLength
        Case 2 '向前搜索
            '设置当前选择的开头
            lngStart = frmDDWordPadMDI.ActiveForm.rtf.SelStart
            lngStart = lngStart + frmDDWordPadMDI.ActiveForm.rtf.SelLength
    End Select
    
    'Call the function to do the find.
    If Not FindString(txtFind.Text, "", lngStart, lngLen) Then
        MsgBox "未找到匹配字符串。", 0, "查找"
    Else
    '    Unload Me
    End If
End Sub

'*************************************************
' 目的:  设置参数来调用函数来替换字符串
'*************************************************
Private Sub cmdReplace_Click()
    Dim lngLen As Long '结束位置
    Dim lngStart As Long '开始位置

    '设置框内的文字的结尾长度
    lngLen = Len(frmDDWordPadMDI.ActiveForm.rtf.Text)

    Select Case cboSearch.ListIndex
        Case 0 '搜索全部
            lngStart = 1
        Case 1 '向后搜索
            lngStart = 1
            '设置当前选择的结尾
            lngLen = frmDDWordPadMDI.ActiveForm.rtf.SelStart
            lngLen = lngLen + frmDDWordPadMDI.ActiveForm.rtf.SelLength
        Case 2 '向前搜索
            '设置当前选择的开头
            lngStart = frmDDWordPadMDI.ActiveForm.rtf.SelStart
            lngStart = lngStart + frmDDWordPadMDI.ActiveForm.rtf.SelLength
    End Select

    '调用函数来替换
    If Not FindString(txtFind.Text, txtReplace.Text, lngStart, lngLen) Then
        MsgBox "未找到匹配字符串。", 0, "替换"
    Else
        Unload Me
    End If
End Sub

'*************************************************
' 目的:  调用函数替换文字,并且调用它直到没有更多
'        的可替换的文字存在
'*************************************************
Private Sub cmdReplaceAll_Click()
    Dim lngLen As Long '结束位置
    Dim lngStart As Long '开始位置
    Dim strMsg As String '提示的临时字符串
    '建造警告提示
    strMsg = "这个程序将从你的文档开头开始替换所"
    strMsg = strMsg & " 有可替换的文字。是否继续?"
    '提示用户是否确定
    If MsgBox(strMsg, vbYesNo, "Are You Sure?") = vbYes Then
        '用户确定,替换所有文字
        Do
            If lngStart = 0 Then
                lngStart = 1
            Else
                '设置新的开始位置和结束位置
                lngStart = frmDDWordPadMDI.ActiveForm.rtf.SelStart
                lngStart = lngStart + frmDDWordPadMDI.ActiveForm.rtf.SelLength
            End If
            '设置文档的末尾
            lngLen = Len(frmDDWordPadMDI.ActiveForm.rtf.Text)
        '循环直到替换完成
        Loop While FindString(txtFind.Text, txtReplace.Text, lngStart, lngLen)
    End If
    ' unload form
    Unload Me
End Sub


'*************************************************
' 目的:  初始化窗体
'*************************************************
Private Sub Form_Load()
    '设置默认值为“全部”
    cboSearch.ListIndex = 0
End Sub


'*************************************************
' 目的:  使按钮有效或无效
'*************************************************
Private Sub txtFind_Change()
    If Len(txtFind.Text) > 0 Then
        '查找文字存在,使“查找下一个”按钮有效
        cmdFindNext.Enabled = True
    Else
        '查找文字不存在,使“查找下一个”按钮无效
        cmdFindNext.Enabled = False
    End If
End Sub


'*************************************************
' 目的:  选择框中的所有内容
'*************************************************
Private Sub txtFind_GotFocus()
    txtFind.SelStart = 0
    txtFind.SelLength = Len(txtFind.Text)
End Sub


'*************************************************
' 目的:  使按钮有效或无效
'*************************************************
Private Sub txtReplace_Change()
    If Len(txtReplace.Text) > 0 Then
        '查找文字存在,使“查找下一个”按钮有效
        cmdReplace.Enabled = True
        cmdReplaceAll.Enabled = True
    Else
        '查找文字不存在,使“查找下一个”按钮无效
        cmdReplace.Enabled = False
        cmdReplaceAll.Enabled = False
    End If
End Sub

'*************************************************
' 目的:  选择框中的所有内容
'*************************************************
Private Sub txtReplace_GotFocus()
    txtReplace.SelStart = 0
    txtReplace.SelLength = Len(txtReplace.Text)
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -