📄 form1.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "richtx32.ocx"
Begin VB.Form Form1
Caption = "记事本"
ClientHeight = 5010
ClientLeft = 3435
ClientTop = 3255
ClientWidth = 6615
LinkTopic = "Form1"
ScaleHeight = 5010
ScaleWidth = 6615
Begin RichTextLib.RichTextBox RichTextBox1
Height = 4695
Left = 0
TabIndex = 1
Top = 0
Width = 6615
_ExtentX = 11668
_ExtentY = 8281
_Version = 393217
Enabled = -1 'True
ScrollBars = 3
TextRTF = $"Form1.frx":0000
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 1920
Top = 1920
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin MSComctlLib.StatusBar StatusBar1
Align = 2 'Align Bottom
Height = 300
Left = 0
TabIndex = 0
Top = 4710
Width = 6615
_ExtentX = 11668
_ExtentY = 529
_Version = 393216
BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
NumPanels = 2
BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Alignment = 1
AutoSize = 2
EndProperty
BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628}
AutoSize = 1
Object.Width = 8599
EndProperty
EndProperty
End
Begin VB.Menu menuFile
Caption = "文件(&F)"
Begin VB.Menu MenuFileNew
Caption = "新建(&N)"
End
Begin VB.Menu menuFileOpen
Caption = "打开(&O)"
End
Begin VB.Menu menuFileSave
Caption = "保存(&S)"
End
Begin VB.Menu menuFileSaveAs
Caption = "另存为(&A)"
End
Begin VB.Menu menuFileSplit1
Caption = "-"
End
Begin VB.Menu menuFilePage
Caption = "页面设置(&U)"
End
Begin VB.Menu menuFilePrint
Caption = "打印(&P)"
End
Begin VB.Menu menuFileSplit2
Caption = "-"
End
Begin VB.Menu menuFileExit
Caption = "退出(&X)"
End
End
Begin VB.Menu menuEdit
Caption = "编辑(&E)"
Begin VB.Menu menuEditUndo
Caption = "撤销(&U)"
End
Begin VB.Menu menuEditSplit1
Caption = "-"
End
Begin VB.Menu menuEditCut
Caption = "剪切(&T)"
End
Begin VB.Menu menuEditCopy
Caption = "复制(&C)"
End
Begin VB.Menu menuEditPaste
Caption = "粘贴(&P)"
End
Begin VB.Menu menuEditDelete
Caption = "删除(&L)"
End
Begin VB.Menu menuEditSplit2
Caption = "-"
End
Begin VB.Menu menuEditFind
Caption = "查找(&F)"
End
Begin VB.Menu menuEditNext
Caption = "查找下一个(&N)"
End
Begin VB.Menu menuEditReplace
Caption = "替换(&R)"
End
Begin VB.Menu menuEditGoto
Caption = "转到(&G)"
End
Begin VB.Menu menuEditSplit3
Caption = "-"
End
Begin VB.Menu menuEditAll
Caption = "全选(&A)"
End
Begin VB.Menu menuEditDate
Caption = "日期/时间(&D)"
End
End
Begin VB.Menu menuFormat
Caption = "格式(&O)"
Begin VB.Menu menuFormatAuto
Caption = "自动换行(&W)"
End
Begin VB.Menu menuFormatFont
Caption = "字体(&F)"
End
End
Begin VB.Menu menuView
Caption = "查看(&V)"
Begin VB.Menu menuViewState
Caption = "状态栏(&S)"
End
End
Begin VB.Menu menuHelp
Caption = "帮助(&H)"
Begin VB.Menu menuHelpTopic
Caption = "帮助主题(&H)"
End
Begin VB.Menu menuHelpSplit1
Caption = "-"
End
Begin VB.Menu menuHelpAbout
Caption = "关于(&A)"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim FileStr As String '全局文件字符串变量
Dim FileName As String '全局文件名称
Dim FileChanged As Boolean '指示文件是否被修改
Dim UndoText As String
Private Sub Command1_Click()
End Sub
Private Sub Form_Load()
FileName = ""
FileChanged = False
FileStr = ""
End Sub
Private Sub Form_Unload(Cancel As Integer)
If FileChanged Then
i = MsgBox("文件已改变,是否保存对文件的修改", vbYesNoCancel, "文件未保存")
If i = vbYes Then
menuFileSave_Click
FileChanged = False
End
End If
If i = vbNo Then
End
End If
End If
End Sub
Private Sub menuEditCopy_Click()
Clipboard.SetText RichTextBox1.SelText
End Sub
Private Sub menuEditCut_Click()
UndoText = RichTextBox1.Text
FileChanged = True
Clipboard.Clear
Clipboard.SetText RichTextBox1.SelText
RichTextBox1.SelText = ""
End Sub
Private Sub menuEditDelete_Click()
UndoText = RichTextBox1.Text
FileChanged = True
RichTextBox1.SelText = ""
End Sub
Private Sub menuEditPaste_Click()
UndoText = RichTextBox1.Text
FileChanged = True
RichTextBox1.SelText = Clipboard.GetText
End Sub
Private Sub menuEditUndo_Click()
RichTextBox1.Text = ""
RichTextBox1.Text = UndoText
'menuEditUndo.Enabled = False
End Sub
Private Sub menuFileExit_Click()
If FileChanged Then
i = MsgBox("文件已改变,是否保存对文件的修改", vbYesNoCancel, "文件未保存")
If i = vbYes Then
menuFileSave_Click
FileChanged = False
End
End If
If i = vbNo Then
End
End If
End If
End Sub
Private Sub MenuFileNew_Click()
If FileName <> "" Then
If FileChanged = True Then
Open FileName For Output As #1
Print #1, RichTextBox1.Text
Close #1
End If
End If
RichTextBox1.Text = ""
FileStr = ""
FileName = ""
FileChanged = False
StatusBar1.Panels(1).Text = "新建文件"
StatusBar1.Panels(2).Text = "尚未命名保存"
End Sub
Private Sub menuFileOpen_Click()
If FileChanged Then
i = MsgBox("文件已改变,是否保存对文件的修改", vbYesNoCancel, "文件未保存")
If i = vbYes Then
menuFileSave_Click
End If
If i = vbCancel Then
Exit Sub
End If
End If
CommonDialog1.Filter = "Text Files (*.TXT)|*.txt|All Files (*.*)|*.*"
CommonDialog1.Flags = &H4
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then Exit Sub
Open CommonDialog1.FileName For Input As #1
FileStr = ""
Do Until EOF(1)
Line Input #1, TempStr
FileStr = FileStr & TempStr & Chr$(13) & Chr$(10)
Loop
Close #1
Form1.Caption = CommonDialog1.FileTitle
RichTextBox1.Text = ""
RichTextBox1.Text = FileStr
FileName = CommonDialog1.FileName
FileChanged = False
StatusBar1.Panels(1).Text = "打开文件"
StatusBar1.Panels(2).Text = FileName
End Sub
Private Sub menuFilePrint_Click()
On Error GoTo PrintCanceled:
CommonDialog1.Flags = DefaultFlags
CommonDialog1.ShowPrinter
Printer.Copies = CommonDialog1.Copies
Printer.Print RichTextBox1.Text
StatusBar1.Panels(1).Text = "文件已打印"
StatusBar1.Panels(2).Text = FileName
PrintCanceled:
End Sub
Private Sub menuFileSave_Click()
If FileName = "" Then
menuFileSaveAs_Click
Else
If FileChanged Then
Open FileName For Output As #1
Print #1, RichTextBox1.Text
Close #1
FileChanged = False
StatusBar1.Panels(1).Text = "文件已保存"
StatusBar1.Panels(2).Text = FileName
End If
End If
End Sub
Private Sub menuFileSaveAs_Click()
On Error GoTo SaveCancelled
CommonDialog1.Filter = "Text Files (*.TXT)|*.txt|All Files (*.*)|*.*"
CommonDialog1.Flags = &H4
CommonDialog1.ShowSave
If CommonDialog1.FileName = "" Then Exit Sub
Open CommonDialog1.FileName For Output As #1
Print #1, RichTextBox1.Text
Close #1
Form1.Caption = CommonDialog1.FileTitle
FileName = CommonDialog1.FileName
FileChanged = False
StatusBar1.Panels(1).Text = "文件已存储"
StatusBar1.Panels(2).Text = FileName
SaveCancelled:
End Sub
Private Sub RichTextBox1_Change()
FileChanged = True
StatusBar1.Panels(1).Text = "文件已修改"
StatusBar1.Panels(2).Text = "编辑文件"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -