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

📄 findfrm-f3.frm

📁 一个用VB实现的简单的记事本程序
💻 FRM
字号:
VERSION 5.00
Begin VB.Form FindFrm 
   Caption         =   "字符查找"
   ClientHeight    =   1545
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5175
   Icon            =   "FindFrm-f3.frx":0000
   LinkTopic       =   "Form3"
   ScaleHeight     =   1545
   ScaleWidth      =   5175
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command3 
      Caption         =   "查找下一个"
      Height          =   375
      Left            =   3840
      TabIndex        =   5
      Top             =   600
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Height          =   285
      Left            =   120
      TabIndex        =   0
      Top             =   480
      Width           =   3615
   End
   Begin VB.CheckBox Check1 
      Caption         =   "区分大小写"
      Height          =   195
      Left            =   480
      TabIndex        =   3
      Top             =   960
      Width           =   1335
   End
   Begin VB.CommandButton Command1 
      Caption         =   "查  找"
      Height          =   375
      Left            =   3840
      TabIndex        =   2
      Top             =   120
      Width           =   1095
   End
   Begin VB.CommandButton Command2 
      Caption         =   "取  消"
      Height          =   375
      Left            =   3840
      TabIndex        =   1
      Top             =   1080
      Width           =   1095
   End
   Begin VB.Label Label1 
      Caption         =   "查找:"
      Height          =   255
      Left            =   120
      TabIndex        =   4
      Top             =   240
      Width           =   1695
   End
End
Attribute VB_Name = "FindFrm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim FindStr As String
Dim StartPos As Integer
Sub FindString(ByVal SourceStr As String, ByVal SearchStr As String, ByVal mode As Integer, DesStr As String, FindPos As Integer)
   '从SourceStr中查找子串SearchStr
   'Mode为1时不区分大小写,否则,区分大小写
   'DesStr是下一次查找的范围
   'FindPos返回查找到的子串的第一个字符的位置
   
   If mode = 1 Then
     FindPos = InStr(1, SourceStr, SearchStr)
   Else
     FindPos = InStr(1, SourceStr, SearchStr, vbTextCompare)
   End If
   
   If FindPos = 0 Then
      DesStr = ""
      Exit Sub
   End If
   
   DesStr = Mid(SourceStr, FindPos + 1)
End Sub

Private Sub Check1_Click()
    '单击“区分大小写”复选框,设置查找方式
    If Check1.Value = 1 Then
        MatchCase = True
    Else
        MatchCase = False
    End If
End Sub

Private Sub Command1_Click()
    '单击“查找”按钮的处理过程:
    '1--根据是否“区分大小写”进行不同方式地查找
    '2--如果找到,显示被找到的字符,否则,提示未找到信息
    

    If MatchCase = True Then         '如果以“区分大小写”方式查找
        Call FindString(FrmMain.RichTextBox1.Text, Text1.Text, 1, FindStr, Pos)
    Else
        Call FindString(FrmMain.RichTextBox1.Text, Text1.Text, 0, FindStr, Pos)
    End If
    
    If Pos <> 0 Then                 '如果找到字符,则显示之
        FrmMain.RichTextBox1.SelStart = Pos - 1
        FrmMain.RichTextBox1.SelLength = Len(Text1.Text)
        FrmMain.SetFocus
        StartPos = Pos - 1           '记录找到字符前面的字符个数
        
        '使“查找”按钮无效,“查找下一个”按钮有效,
        Command1.Enabled = False
        Command3.Enabled = True
    Else
        MsgBox "没有找到字符 " & Chr$(34) & Text1.Text & Chr$(34)
    End If
End Sub

Private Sub Command2_Click()
    '单击“取消”按钮,退出“查找”窗体
    Unload Me
End Sub

Private Sub Command3_Click()
'单击“查找下一个”按钮时

Dim TempStr As String              '记录下一次查找字符串的临时变量

    If MatchCase = True Then         '如果以“区分大小写”方式查找
       Call FindString(FindStr, Text1.Text, 1, TempStr, Pos)
    Else
       Call FindString(FindStr, Text1.Text, 0, TempStr, Pos)
    End If
    FindStr = TempStr

    If Pos <> 0 Then                 '如果找到字符,则显示之
        StartPos = Pos + StartPos
        FrmMain.RichTextBox1.SelStart = StartPos
        FrmMain.RichTextBox1.SelLength = Len(Text1.Text)
        FrmMain.SetFocus
    Else
        MsgBox "没有找到字符 " & Chr$(34) & Text1.Text & Chr$(34)
        Command3.Enabled = False
        Command1.Enabled = True
    End If

End Sub

Private Sub Form_Load()
    '加载“查找”窗体的初始化设置
    Pos = 0
    StartPos = 0
    If MatchCase = True Then Check1.Value = 1
    FindStr = FrmMain.RichTextBox1.Text
    Command3.Enabled = False
    
    Dim retValue As Long
    Const HWND_TOPMOST = -1
    Const SWP_SHOWWINDOW = &H40
    retValue = SetWindowPos(Me.hwnd, HWND_TOPMOST, _
    Me.CurrentX, Me.CurrentY, 360, 130, SWP_SHOWWINDOW)
End Sub

Private Sub text1_Change()
    '当文本框内容发生变化,获取要查找的字符串
    SearchStr = Text1.Text
End Sub

⌨️ 快捷键说明

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