📄 textedit.frm
字号:
VERSION 5.00
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 = 6630
ClientLeft = 1440
ClientTop = 1560
ClientWidth = 9645
LinkTopic = "Form1"
PaletteMode = 1 'UseZOrder
ScaleHeight = 6630
ScaleWidth = 9645
Begin MSComDlg.CommonDialog CmdOpen
Left = 6720
Top = 420
_ExtentX = 847
_ExtentY = 847
_Version = 393216
DefaultExt = "txt"
Filter = "RTF Files|*.rtf|Text Files|*.txt|All files|*.*"
End
Begin RichTextLib.RichTextBox RichTextBox1
Height = 6495
Left = 0
TabIndex = 0
Top = 0
Width = 9615
_ExtentX = 16960
_ExtentY = 11456
_Version = 393217
BorderStyle = 0
Enabled = -1 'True
ScrollBars = 2
TextRTF = $"textedit.frx":0000
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin VB.Menu mnuFile
Caption = "文件(&F)"
Begin VB.Menu mnuNew
Caption = "新建(&N)"
Shortcut = ^N
End
Begin VB.Menu mnuOpen
Caption = "打开(&O)"
Shortcut = ^O
End
Begin VB.Menu mnuSave
Caption = "保存(&S)"
Shortcut = ^S
End
Begin VB.Menu Sep1
Caption = "-"
End
Begin VB.Menu mnuFont
Caption = "字体(&T)"
End
Begin VB.Menu mnuPrint
Caption = "打印(&P)"
Shortcut = ^P
End
Begin VB.Menu Sep2
Caption = "-"
End
Begin VB.Menu mnuExit
Caption = "退出(&X)"
End
End
Begin VB.Menu mnuEdit
Caption = "编辑(&E)"
Begin VB.Menu mnuFind
Caption = "查找(&F)"
Shortcut = ^F
End
Begin VB.Menu mnuNext
Caption = "查找下一个(&N)"
Shortcut = {F3}
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
Public sFind As String
Private Sub Form_Resize()
'如果窗体不处于最小化RichTextBox1状态,改变RichTextBox1大小以适应窗体大小变化
If Form1.WindowState <> 1 Then
RichTextBox1.Width = Form1.Width - 135
If Form1.Height < 1200 Then
Form1.Height = 1200
End If
RichTextBox1.Height = Form1.Height - 675
End If
End Sub
'当“退出”菜单项被点击时
Private Sub mnuExit_Click()
Unload Me
End Sub
'当“查找”菜单项被点击时
Private Sub mnuFind_Click()
sFind = InputBox("Find what?", , sFind)
RichTextBox1.Find sFind
End Sub
'当“字体”菜单项被点击时
Private Sub mnuFont_Click()
CmdOpen.Flags = cdlCFBoth + cdlCFEffects
CmdOpen.ShowFont
'将RichTextBox1的属性根据“字体”对话框的变化作相应设置
'----------------------------------------
'要改变 RichTextBox 控件中的字体特性,可以使用
'SelFontName、SelFontSize 和 SelFontColor 属性。
'----------------------------------------
With RichTextBox1
.SelFontName = CmdOpen.FontName
.SelFontSize = CmdOpen.FontSize
.SelBold = CmdOpen.FontBold
.SelItalic = CmdOpen.FontItalic
.SelStrikeThru = CmdOpen.FontStrikethru
.SelUnderline = CmdOpen.FontUnderline
End With
End Sub
'当“新建”菜单项被点击时,设置为空
Private Sub mnuNew_Click()
RichTextBox1.Text = ""
End Sub
'当“查找下一个”菜单项被点击时
Private Sub mnuNext_Click()
' SelStart属性-返回或设置所选择的文本的起始点;
' 如果没有文本被选中,则指出插入点的位置。
RichTextBox1.SelStart = RichTextBox1.SelStart + RichTextBox1.SelLength + 1
RichTextBox1.Find sFind, , Len(RichTextBox1)
End Sub
'当“打开”菜单项被点击时
Private Sub mnuOpen_Click()
CmdOpen.ShowOpen
RichTextBox1.LoadFile (CmdOpen.FileName)
End Sub
'当“打印”菜单项被点击时
Private Sub mnuPrint_Click()
CmdOpen.Flags = cdlPDReturnDC + cdlPDNoPageNums
If RichTextBox1.SelLength = 0 Then
CmdOpen.Flags = CmdOpen.Flags + cdlPDAllPages
Else
CmdOpen.Flags = CmdOpen.Flags + cdlPDSelection
End If
CmdOpen.ShowPrinter
'将 RichTextBox 控件中格式化文本发送给设备进行打印。
RichTextBox1.SelPrint CmdOpen.hDC
End Sub
'当“保存”菜单项被点击时
Private Sub mnuSave_Click()
CmdOpen.ShowSave
'RichTextBox的SaveFile方法,保存文本
RichTextBox1.SaveFile (CmdOpen.FileName)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -