📄 7-2s.frm
字号:
VERSION 5.00
Begin VB.Form frmNotePad
Caption = "无标题"
ClientHeight = 3990
ClientLeft = 1515
ClientTop = 3315
ClientWidth = 5670
BeginProperty Font
Name = "Arial"
Size = 9
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
MDIChild = -1 'True
ScaleHeight = 3990
ScaleMode = 0 'User
ScaleWidth = 101.07
Begin VB.TextBox Text1
Height = 3975
HideSelection = 0 'False
Left = 0
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 0
Top = 0
Width = 5655
End
Begin VB.Menu mnuFile
Caption = "文件(&F)"
Begin VB.Menu mnuFileNew
Caption = "新建(&N)"
End
Begin VB.Menu mnuFileOpen
Caption = "打开(&O)..."
End
Begin VB.Menu mnuFileClose
Caption = "关闭(&C)"
End
Begin VB.Menu mnuFileSave
Caption = "保存(&S)"
End
Begin VB.Menu mnuFileSaveAs
Caption = "另存为(&A)..."
End
Begin VB.Menu mnuFSep
Caption = "-"
End
Begin VB.Menu mnuFileExit
Caption = "退出(&X)"
End
Begin VB.Menu mnuRecentFile
Caption = "-"
Index = 0
Visible = 0 'False
End
Begin VB.Menu mnuRecentFile
Caption = "最近处理文件1"
Index = 1
Visible = 0 'False
End
Begin VB.Menu mnuRecentFile
Caption = "最近处理文件2"
Index = 2
Visible = 0 'False
End
Begin VB.Menu mnuRecentFile
Caption = "最近处理文件3"
Index = 3
Visible = 0 'False
End
Begin VB.Menu mnuRecentFile
Caption = "最近处理文件4"
Index = 4
Visible = 0 'False
End
Begin VB.Menu mnuRecentFile
Caption = "最近处理文件5"
Index = 5
Visible = 0 'False
End
End
Begin VB.Menu mnuEdit
Caption = "编辑(&E)"
Begin VB.Menu mnuEditCut
Caption = "剪切(&T)"
Shortcut = ^X
End
Begin VB.Menu mnuEditCopy
Caption = "复制(&C)"
Shortcut = ^C
End
Begin VB.Menu mnuEditPaste
Caption = "粘贴(&P)"
Shortcut = ^V
End
Begin VB.Menu mnuEditDelete
Caption = "删除(&L)"
Shortcut = {DEL}
End
Begin VB.Menu mnuESep1
Caption = "-"
End
Begin VB.Menu mnuEditSelectAll
Caption = "全部选定(&A)"
End
Begin VB.Menu mnuEditTime
Caption = "时间/日期(&D)"
End
End
Begin VB.Menu mnuSearch
Caption = "搜索(&S)"
Begin VB.Menu mnuSearchFind
Caption = "查找(&F)"
End
Begin VB.Menu mnuSearchFindNext
Caption = "查找下一个(&N)"
Shortcut = {F3}
End
End
Begin VB.Menu mnuOptions
Caption = "选项(&O)"
Begin VB.Menu mnuOptionsToolbar
Caption = "工具栏(&T)"
End
Begin VB.Menu mnuFont
Caption = "字体(&F)"
Begin VB.Menu mnuFontName
Caption = "字体名称"
Index = 0
End
End
End
Begin VB.Menu mnuWindow
Caption = "窗口(&W)"
WindowList = -1 'True
Begin VB.Menu mnuWindowCascade
Caption = "层叠(&C)"
End
Begin VB.Menu mnuWindowTile
Caption = "平铺(&T)"
End
Begin VB.Menu mnuWindowArrange
Caption = "排列图标(&A)"
End
End
End
Attribute VB_Name = "frmNotePad"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'*** MDI 记事本应用程序示例子窗体 ***
'**********************************************************
Option Explicit
Private Sub Form_Load()
Dim i As Integer ' 计数器变量。
' 将第一种字体名赋值给“字体”菜单项,再循环系统字体集合,添加到菜单。
mnuFontName(0).Caption = Screen.Fonts(0)
For i = 1 To Screen.FontCount - 1
Load mnuFontName(i)
mnuFontName(0).Caption = Screen.Fonts(i)
Next
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim strMsg As String
Dim strFilename As String
Dim intResponse As Integer
' 判断文本是否已经被改变。
If FState(Me.Tag).Dirty Then
strFilename = Me.Caption
strMsg = "[" & strFilename & "] 中文本已经改变,"
strMsg = strMsg & vbCrLf
strMsg = strMsg & "保存改变吗?"
intResponse = MsgBox(strMsg, 51, frmMDI.Caption)
Select Case intResponse
Case 6 ' 用户选择“是”。
If Left(Me.Caption, 8) = "无标题" Then
' 文件尚未被保存。
strFilename = "untitled.txt"
' 获得 strFilename,并调用保存过程,GetstrFilename 。
strFilename = GetFileName(strFilename)
Else
' 窗体标题包含所打开的文件名。
strFilename = Me.Caption
End If
' 调用保存过程
' 如果 strFilename = Empty,用户在“另存为”对话框中选择“取消”;否则保存该文件。
If strFilename <> "" Then
SaveFileAs strFilename
End If
Case 7 ' 用户选择“否”,卸载文件。
Cancel = False
Case 2 ' 用户选择“取消”,取消卸载。
Cancel = True
End Select
End If
End Sub
Private Sub Form_Resize()
' 将文本框充满当前子窗体的内部区域。
Text1.Height = ScaleHeight
Text1.Width = ScaleWidth
End Sub
Private Sub Form_Unload(Cancel As Integer)
' 将当前窗体实例显示为已删除。
FState(Me.Tag).Deleted = True
' 如果不存在记事本窗口,隐含工具栏编辑按钮。
If Not AnyPadsLeft() Then
frmMDI.imgCutButton.Visible = False
frmMDI.imgCopyButton.Visible = False
frmMDI.imgPasteButton.Visible = False
' 切换全局工具状态变量
gToolsHidden = True
' 调用获得当前最近使用的文件列表的过程
GetRecentFiles
End If
End Sub
Private Sub mnuEditCopy_Click()
' 调用复制过程
EditCopyProc
End Sub
Private Sub mnuEditCut_Click()
' 调用剪切过程
EditCutProc
End Sub
Private Sub mnuEditDelete_Click()
' 如果鼠标指针不在记事本结尾处...
If Screen.ActiveControl.SelStart <> Len(Screen.ActiveControl.Text) Then
' 如果什么也没有选定,将选定长度设为 1
If Screen.ActiveControl.SelLength = 0 Then
Screen.ActiveControl.SelLength = 1
' 如果鼠标指针在空行,将选定长度设为 2 。
If Asc(Screen.ActiveControl.SelText) = 13 Then
Screen.ActiveControl.SelLength = 2
End If
End If
' 删除选定文本。
Screen.ActiveControl.SelText = ""
End If
End Sub
Private Sub mnuEditPaste_Click()
' 调用粘贴过程。
EditPasteProc
End Sub
Private Sub mnuEditSelectAll_Click()
' 使用 SelStart 和 SelLength 选定文本。
frmMDI.ActiveForm.Text1.SelStart = 0
frmMDI.ActiveForm.Text1.SelLength = Len(frmMDI.ActiveForm.Text1.Text)
End Sub
Private Sub mnuEditTime_Click()
' 在当前光标处插入当前时间和日期。
Text1.SelText = Now
End Sub
Private Sub mnuFileClose_Click()
' 卸载窗体。
Unload Me
End Sub
Private Sub mnuFileExit_Click()
' 要卸载 MDI 窗体,向每个子窗体,然后是 MDI 主窗体调用 QueryUnload 事件。
' 在 QueryUnload 事件中把 Cancel 参数设置为 True 都会取消卸载。
Unload frmMDI
End Sub
Private Sub mnuFileNew_Click()
' 调用新建窗体过程
FileNew
End Sub
Private Sub mnuFontName_Click(index As Integer)
' 将选定字体赋值给 textbox 的 fontname 属性。
Text1.FontName = mnuFontName(index).Caption
End Sub
Private Sub mnuFileOpen_Click()
' 调用文件打开过程。
FileOpenProc
End Sub
Private Sub mnuFileSave_Click()
Dim strFilename As String
If Left(Me.Caption, 8) = "Untitled" Then
' 文件尚未被保存。
' 获取文件名并调用保存过程,GetFileName 。
strFilename = GetFileName(strFilename)
Else
' 窗体标题包含打开的文件名。
strFilename = Me.Caption
End If
' 调用保存过程。
' 如果 Filename = Empty,用户在“另存为”对话框中选择“取消”;否则保存该文件。
If strFilename <> "" Then
SaveFileAs strFilename
End If
End Sub
Private Sub mnuFileSaveAs_Click()
Dim strSaveFileName As String
Dim strDefaultName As String
' 将窗体标题赋值给变量。
strDefaultName = Me.Caption
If Left(Me.Caption, 8) = "无标题" Then
' 文件尚未被保存。
' 获取文件名并调用保存过程,strSaveFileName 。
strSaveFileName = GetFileName("Untitled.txt")
If strSaveFileName <> "" Then SaveFileAs (strSaveFileName)
' 更新“文件”菜单控件数组中最近打开的文件列表。
UpdateFileMenu (strSaveFileName)
Else
' 窗体标题包含打开的文件名。
strSaveFileName = GetFileName(strDefaultName)
If strSaveFileName <> "" Then SaveFileAs (strSaveFileName)
' 更新“文件”菜单控件数组中最近打开的文件列表。
UpdateFileMenu (strSaveFileName)
End If
End Sub
Private Sub mnuOptions_Click()
' 切换 Checked 属性来匹配 .Visible 属性。
mnuOptionsToolbar.Checked = frmMDI.picToolbar.Visible
End Sub
Private Sub mnuOptionsToolbar_Click()
' 调用工具栏过程,传递一个对该窗体实例的引用。
OptionsToolbarProc Me
End Sub
Private Sub mnuRecentFile_Click(index As Integer)
' 调用文件打开过程,传递一个对选定的文件名的引用。
OpenFile (mnuRecentFile(index).Caption)
' 更新“文件”菜单控件数组中最近打开的文件列表。
GetRecentFiles
End Sub
Private Sub mnuSearchFind_Click()
' 如果文本框中有文本,把它赋值给“查找”窗体中的文本框,
' 否则赋值上一次搜索文本的值。
If Me.Text1.SelText <> "" Then
frmFind.Text1.Text = Me.Text1.SelText
Else
frmFind.Text1.Text = gFindString
End If
' 设置全局变量为从头部开始。
gFirstTime = True
' 设置区分大小写复选框以匹配全局变量。
If (gFindCase) Then
frmFind.chkCase = 1
End If
' 显示“查找”窗体。
frmFind.Show vbModal
End Sub
Private Sub mnuSearchFindNext_Click()
' 如果全局变量不为空,调用查找过程;否则调用“查找”菜单。
If Len(gFindString) > 0 Then
FindIt
Else
mnuSearchFind_Click
End If
End Sub
Private Sub mnuWindowArrange_Click()
' 对任何已经最小化的子窗体排列图标。
frmMDI.Arrange vbArrangeIcons
End Sub
Private Sub mnuWindowCascade_Click()
' 层叠子窗体。
frmMDI.Arrange vbCascade
End Sub
Private Sub mnuWindowTile_Click()
' 平铺子窗体。
frmMDI.Arrange vbTileHorizontal
End Sub
Private Sub Text1_Change()
' 设置全局变量来显示文本已经改变。
FState(Me.Tag).Dirty = True
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -