📄 not1.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1
Caption = "记事本"
ClientHeight = 4335
ClientLeft = 165
ClientTop = 735
ClientWidth = 6255
LinkTopic = "Form1"
ScaleHeight = 4335
ScaleWidth = 6255
StartUpPosition = 3 '窗口缺省
Begin MSComDlg.CommonDialog CommonDialog1
Left = 5640
Top = 0
_ExtentX = 847
_ExtentY = 847
_Version = 393216
Color = 16777215
DefaultExt = "TXT"
DialogTitle = "文件"
Filter = "文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*"
FontName = "宋体"
FontSize = 10.5
InitDir = "."
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 2415
Left = 1320
MaxLength = 32768
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 960
Width = 3135
End
Begin VB.Menu File
Caption = "文件"
Begin VB.Menu New
Caption = "新建(&N)"
End
Begin VB.Menu Open
Caption = "打开(&O)"
End
Begin VB.Menu Save
Caption = "保存(&S)"
End
Begin VB.Menu Close
Caption = "关闭(&C)"
End
Begin VB.Menu Sep1
Caption = "-"
End
Begin VB.Menu Exit
Caption = "退出"
Shortcut = ^X
End
End
Begin VB.Menu Edit
Caption = "编辑"
Begin VB.Menu Cut
Caption = "剪切"
End
Begin VB.Menu Copy
Caption = "复制"
End
Begin VB.Menu Paste
Caption = "粘贴"
End
Begin VB.Menu Delete
Caption = "删除"
End
Begin VB.Menu Sep2
Caption = "-"
End
Begin VB.Menu DataTime
Caption = "日期/时间"
End
End
Begin VB.Menu Option
Caption = "选项"
Begin VB.Menu Fontcolor
Caption = "字体颜色"
End
Begin VB.Menu Sep4
Caption = "-"
End
Begin VB.Menu BackColor
Caption = "背景色"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim FileName As String
Private Sub BackColor_Click()
CommonDialog1.ShowColor
Text1.BackColor = CommonDialog1.Color
End Sub
Private Sub Close_Click()
Dim FileNum As Integer
If Len(FileName) > 0 Then
'有输入文件名
FileNum = FreeFile() '获得可用文件号
Open FileName For Output As FileNum '打开输出文件
'如果无指定文件,则创建新文件
Print #FileNum, Text1.Text '输出文本
Close FileNum '关闭文件
End If
Text1.Text = ""
FileName = ""
End Sub
Private Sub Copy_Click()
Clipboard.SetText Text1.SelText '复制文本到剪裁板
End Sub
Private Sub Cut_Click()
Clipboard.SetText Text1.SelText '复制文本到剪裁板
Text1.SelText = "" '清选择的文本
End Sub
Private Sub DataTime_Click()
Text1.SelText = Now
End Sub
Private Sub Delete_Click()
Text1.SelText = "" '清选择的文本
End Sub
Private Sub Edit_Click()
'当程序显示“编辑”子菜单前,触发该程序
If Text1.SelLength > 0 Then
'文本框中有选中的文本
Cut.Enabled = True
Copy.Enabled = True
Delete.Enabled = True
Else
Cut.Enabled = False
Copy.Enabled = False
Delete.Enabled = False
End If
If Len(Clipboard.GetText()) > 0 Then
'剪裁板中有文本数据
Paste.Enabled = True
Else
'没有可粘贴的文本
Paste.Enabled = False
End If
End Sub
Private Sub Exit_Click()
Unload Me
End Sub
Private Sub Fontcolor_Click()
CommonDialog1.ShowColor
Text1.ForeColor = CommonDialog1.Color
End Sub
Private Sub Form_Resize()
'修改文本框大小
Text1.Top = Me.ScaleTop
Text1.Left = Me.ScaleLeft
Text1.Width = Me.ScaleWidth
Text1.Height = Me.ScaleHeight
End Sub
Private Sub New_Click()
FileName = ""
Text1 = ""
End Sub
Private Sub Open_Click()
Dim FileNum As Integer
Dim buffer As String
Dim buffer1 As String
Dim FileSize As Long
Dim MaxLen As Long
MaxLen = 32768 '文件最大长度
CommonDialog1.ShowOpen '显示"打开文件"对话框
If Len(CommonDialog1.FileName) > 0 Then
'有输入文件名
FileName = CommonDialog1.FileName '保存文件名
FileSize = FileLen(FileName) '获得文件长度
If FileSize > MaxLen Then
'文件超长
MsgBox "该文件过大,只能显示部分文本", , "警告"
Exit Sub
End If
FileNum = FreeFile() '获得可用文件号
Open FileName For Input As FileNum '以顺序输入方式打开文件
Do While Not EOF(FileNum) And Len(buffer) < MaxLen '读必须文本小于 32K
Line Input #FileNum, buffer1 '读一行文字
buffer = buffer + buffer1 + Chr(13) + Chr(10) '加入回车换行符
Loop '循环体
Close FileNum '关闭文件
Text1.Text = buffer '显示文本
buffer = "" '释放内存
buffer1 = ""
End If
End Sub
Private Sub Paste_Click()
Text1.SelText = Clipboard.GetText
End Sub
Private Sub Save_Click()
Dim FileNum As Integer '文件句柄号
CommonDialog1.ShowSave '显示保存对话框
If Len(CommonDialog1.FileName) > 0 Then
'有输入文件名
FileName = CommonDialog1.FileName '保存文件名
FileNum = FreeFile() '获得可用文件号
Open FileName For Output As FileNum '打开输出文件
'如果无指定文件,则创建新文件
Print #FileNum, Text1.Text '输出文本
Close FileNum '关闭文件
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -