📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form frmEdit
Caption = "文本编辑器"
ClientHeight = 3345
ClientLeft = 165
ClientTop = 735
ClientWidth = 5385
LinkTopic = "Form1"
ScaleHeight = 3345
ScaleWidth = 5385
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtEdit
Height = 1695
Left = 480
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 360
Width = 3015
End
Begin VB.Menu mnuFile
Caption = "文件(&F)"
Begin VB.Menu mnuFileNew
Caption = "新建(&N)"
Shortcut = ^N
End
Begin VB.Menu mnuFileOpen
Caption = "打开...(&O)"
Shortcut = ^O
End
Begin VB.Menu mnuFileSave
Caption = "保存(&S)"
Shortcut = ^S
End
Begin VB.Menu mnuFileSaveAs
Caption = "另存为...(&A)"
End
Begin VB.Menu numFileSeparator
Caption = "-"
End
Begin VB.Menu mnuFileExit
Caption = "退出(&E)"
End
End
End
Attribute VB_Name = "frmEdit"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim strFileName As String '文件名
Dim blnModified As Boolean '保存后是否编辑过
Private Sub Form_Load()
Caption = "文本编辑器"
End Sub
Private Sub Form_Resize() '使文本框占据整个窗体的客户区
txtEdit.Top = 0: txtEdit.Left = 0
txtEdit.Width = ScaleWidth: txtEdit.Height = ScaleHeight
End Sub
Private Sub mnuFileNew_Click() '新建文件
Dim int1 As Integer
If blnModified Then '如果有未保存的文件,提示保存
int1 = MsgBox("新建文件前是否保存当前文件?", 35, "注意")
If int1 = 6 Then
SaveFile '保存文件
ElseIf int1 = 2 Then
Exit Sub
End If
End If
Caption = "文本编辑器"
txtEdit.Text = ""
strFileName = ""
blnModified = False
End Sub
Private Sub mnuFileOpen_Click() '打开文件
Dim strTemp1 As String, strTemp2 As String
Dim int1 As Integer
If blnModified Then '如果有未保存的文件,提示保存
int1 = MsgBox("打开新文件前是否保存当前文件?", 35, "是否保存")
If int1 = 6 Then
SaveFile '保存文件
ElseIf int1 = 2 Then
Exit Sub
End If
End If
strTemp1 = InputBox("请输入要打开的完整文件名:", "文件名") '输入文件名
If strTemp1 = "" Then
Exit Sub
Else
strFileName = strTemp1
Caption = "文本编辑器:" & strFileName '改变窗体标题
Open strFileName For Input As 1 '从文件中读入文本
Do While Not EOF(1)
Line Input #1, strTemp1 '整行读入
strTemp2 = strTemp2 & strTemp1 & Chr(13) & Chr(10) '行尾加回车和换行
Loop
Close 1
txtEdit.Text = strTemp2
blnModified = False
End If
End Sub
Private Sub mnuFileSave_Click()
SaveFile '保存文件
End Sub
Private Sub mnuFileSaveAs_Click() '另存为
Dim strTemp As String
strTemp = InputBox("请输入完整文件名:", "文件名")
If strTemp = "" Then
Exit Sub
Else
strFileName = strTemp
Caption = "文本编辑器:" & strFileName
SaveFile
End If
End Sub
Private Sub SaveFile() '保存文件
If strFileName = "" Then
strFileName = InputBox("请输入被保存文件的完整文件名:", "文件名")
If strFileName = "" Then
Exit Sub
End If
Caption = "文本编辑器:" & strFileName
End If
Open strFileName For Output As 1
Print #1, txtEdit.Text
Close 1
blnModified = False
End Sub
Private Sub mnuFileExit_Click()
Unload Me
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim int1 As String
If blnModified Then
int1 = MsgBox("文件尚未保存,退出时是否保存?", 35, "注意")
If int1 = 6 Then
SaveFile
ElseIf int1 = 2 Then
Cancel = 1
End If
End If
End Sub
Private Sub txtEdit_Change()
blnModified = True
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -