📄 form2.frm
字号:
VERSION 5.00
Begin VB.Form frmFind
BorderStyle = 4 'Fixed ToolWindow
Caption = "查找"
ClientHeight = 2130
ClientLeft = 4020
ClientTop = 2580
ClientWidth = 7575
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2130
ScaleWidth = 7575
ShowInTaskbar = 0 'False
Begin VB.CommandButton Command3
Caption = "取消"
Height = 375
Left = 5880
TabIndex = 6
Top = 1440
Width = 1335
End
Begin VB.CommandButton Command2
Caption = "替换"
Height = 375
Left = 5880
TabIndex = 5
Top = 960
Width = 1335
End
Begin VB.TextBox Text2
Height = 270
Left = 1680
TabIndex = 4
Top = 1012
Width = 3735
End
Begin VB.CommandButton Command1
Caption = "查找下一个"
Height = 375
Left = 5880
TabIndex = 2
Top = 428
Width = 1335
End
Begin VB.TextBox Text1
Height = 270
Left = 1680
TabIndex = 0
Top = 480
Width = 3735
End
Begin VB.Label Label2
Caption = "替换内容"
Height = 270
Left = 360
TabIndex = 3
Top = 1012
Width = 975
End
Begin VB.Label Label1
Caption = "查找内容:"
Height = 270
Left = 360
TabIndex = 1
Top = 480
Width = 975
End
End
Attribute VB_Name = "frmFind"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim x As Integer
Dim txtClient As RichTextBox
Private Sub Command1_Click()
Dim strlen As Integer
strlen = Len(Text1.Text) '取要查询的字符串的长度
x = main.RichTextBox1.Find(Text1.Text, x + strlen, , 8) 'x为查找到的匹配字符串的位置
If x <> -1 Then 'x不等于1
main.RichTextBox1.SetFocus '光标移到richtextbox1中
main.RichTextBox1.SelStart = x '光标移到匹配字符串的前边
Else: MsgBox "未找到指定字符", vbOKOnly, "未找到" 'x等于1则提示为找到
End If
End Sub
Private Sub Command2_Click() '替换
Dim str As String
main.RichTextBox1.Text = Replace(main.RichTextBox1.Text, Text1.Text, Text2.Text, , , 1) 'replace函数替换,替换后显示在richtextbox中
End Sub
Public Sub FindandReplace(ByRef Tb As RichTextBox) '连接richtextbox控件的子程序
Set txtClient = Tb
frmFind.Show , txtClient.Parent
End Sub
Private Sub Command3_Click() '退出
frmFind.Hide
End Sub
Private Sub Form_Load() '初始化窗体
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Text1_Change()
x = -1 'text1改变后,x初始化为-1
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -