📄 edit.frm
字号:
VERSION 4.00
Begin VB.Form frmEditor
Caption = "Text Editor: Untitled"
ClientHeight = 4020
ClientLeft = 1425
ClientTop = 1650
ClientWidth = 7650
ClipControls = 0 'False
Height = 4710
Left = 1365
LinkTopic = "Form2"
ScaleHeight = 3753.867
ScaleMode = 0 'User
ScaleWidth = 7650
Top = 1020
Width = 7770
Begin VB.TextBox txtEdit
BeginProperty Font
name = "MS Sans Serif"
charset = 0
weight = 400
size = 12
underline = 0 'False
italic = 0 'False
strikethrough = 0 'False
EndProperty
Height = 3420
Left = 0
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 600
Width = 7605
End
Begin ComctlLib.ImageList imgToolbar
Left = 6000
Top = 120
_Version = 65536
_ExtentX = 1005
_ExtentY = 1005
_StockProps = 1
BackColor = -2147483643
ImageWidth = 24
ImageHeight = 22
NumImages = 12
i1 = "edit.frx":0000
i2 = "edit.frx":023F
i3 = "edit.frx":0482
i4 = "edit.frx":06C5
i5 = "edit.frx":0908
i6 = "edit.frx":0B47
i7 = "edit.frx":0D8A
i8 = "edit.frx":0FCD
i9 = "edit.frx":1214
i10 = "edit.frx":145B
i11 = "edit.frx":16A3
i12 = "edit.frx":18EB
End
Begin ComctlLib.Toolbar tlbToolbar
Align = 1 'Align Top
Height = 480
Left = 0
TabIndex = 1
Top = 0
Width = 7650
_Version = 65536
_ExtentX = 13494
_ExtentY = 847
_StockProps = 96
ImageList = "imgToolbar"
ButtonWidth = 464.882
ButtonHeight = 392.283
NumButtons = 11
i1 = "edit.frx":1B33
i2 = "edit.frx":1CB8
i3 = "edit.frx":1E41
i4 = "edit.frx":1FC2
i5 = "edit.frx":2137
i6 = "edit.frx":22C4
i7 = "edit.frx":2449
i8 = "edit.frx":25DA
i9 = "edit.frx":274F
i10 = "edit.frx":28D8
i11 = "edit.frx":2A6E
AlignSet = -1 'True
End
Begin MSComDlg.CommonDialog CMDialog1
Left = 0
Top = 0
_Version = 65536
_ExtentX = 847
_ExtentY = 847
_StockProps = 0
CancelError = -1 'True
End
Begin VB.Menu mnuFile
Caption = "&File"
Begin VB.Menu mnuFileItem
Caption = "&New"
Index = 0
End
Begin VB.Menu mnuFileItem
Caption = "&Open..."
Index = 1
End
Begin VB.Menu mnuFileItem
Caption = "Save &As..."
Index = 2
End
Begin VB.Menu mnuFileItem
Caption = "-"
Index = 3
End
Begin VB.Menu mnuFileItem
Caption = "E&xit"
Index = 4
End
Begin VB.Menu mnuFileArray
Caption = "-"
Index = 0
Visible = 0 'False
End
End
Begin VB.Menu mnuEdit
Caption = "&Edit"
Begin VB.Menu mnuEditItem
Caption = "Cu&t"
Index = 0
Shortcut = ^X
End
Begin VB.Menu mnuEditItem
Caption = "C&opy"
Index = 1
Shortcut = ^C
End
Begin VB.Menu mnuEditItem
Caption = "&Paste"
Index = 2
Shortcut = ^V
End
End
Begin VB.Menu mnuSettings
Caption = "&Settings"
Begin VB.Menu mnuSettingsItem
Caption = "&Colors"
Index = 0
Begin VB.Menu mnuColorsItem
Caption = "&BackColor"
Index = 0
Begin VB.Menu mnuBackColorItem
Caption = "&Red"
Index = 0
End
Begin VB.Menu mnuBackColorItem
Caption = "&Green"
Index = 1
End
Begin VB.Menu mnuBackColorItem
Caption = "&Blue"
Index = 2
End
End
Begin VB.Menu mnuColorsItem
Caption = "&ForeColor"
Index = 1
Begin VB.Menu mnuForeColorItem
Caption = "&Red"
Index = 0
End
Begin VB.Menu mnuForeColorItem
Caption = "&Green"
Index = 1
End
Begin VB.Menu mnuForeColorItem
Caption = "&Blue"
Index = 2
Begin VB.Menu mnuBlueItem
Caption = "&Light Blue"
Index = 0
End
Begin VB.Menu mnuBlueItem
Caption = "&Dark Blue"
Index = 1
Begin VB.Menu mnuDarkBlueItem
Caption = "&Sea Blue"
Index = 0
End
Begin VB.Menu mnuDarkBlueItem
Caption = "&Midnight Blue"
Index = 1
End
End
End
End
End
Begin VB.Menu mnuSettingsItem
Caption = "&Font Sizes"
Index = 1
Begin VB.Menu mnuFontSizesItem
Caption = "12"
Checked = -1 'True
Index = 0
End
Begin VB.Menu mnuFontSizesItem
Caption = "24"
Index = 1
End
End
End
Begin VB.Menu mnuAbout
Caption = "&About..."
End
End
Attribute VB_Name = "frmEditor"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Private Sub Form_Load()
' Change the working directory to the directory where this application is located.
ChDir App.Path
ChDrive App.Path
' Position the text box.
txtEdit.Move 0, tlbToolbar.Height
' The form is horizontally and vertically centered when loaded.
TOP = Screen.Height / 2 - Height / 2
Left = Screen.Width / 2 - Width / 2
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
' The general procedure DoUnLoadPreCheck handles the possible unload options
' for all three forms in this sample application.
DoUnLoadPreCheck UnloadMode
End Sub
Private Sub Form_Resize()
txtEdit.Width = ScaleWidth
txtEdit.Height = ScaleHeight - tlbToolbar.Height
End Sub
Private Sub mnuAbout_Click()
' display the About form with Show method
frmAbout.Show 1
End Sub
Private Sub mnuBackColorItem_Click(Index As Integer)
Select Case Index
Case 0 ' Set BackColor to Red
txtEdit.BackColor = RGB(255, 0, 0)
Case 1 ' Set BackColor to Green
txtEdit.BackColor = RGB(0, 255, 0)
Case 2 ' Set BackColor to Blue
txtEdit.BackColor = RGB(0, 0, 255)
End Select
End Sub
Private Sub mnuBlueItem_Click(Index As Integer)
' If the user chooses Light Blue, then set the Forecolor to light
' blue, otherwise do nothing.
If Index = 0 Then
txtEdit.ForeColor = RGB(0, 150, 255)
End If
End Sub
Private Sub mnuDarkBlueItem_Click(Index As Integer)
Select Case Index
Case 0
' Set ForeColor to Sea Blue.
txtEdit.ForeColor = RGB(0, 50, 175)
Case 1
' Set ForeColor to Midnight Blue.
txtEdit.ForeColor = RGB(0, 0, 255)
End Select
End Sub
Private Sub mnuEdit_Click()
' Disable Cut and Copy if no text selected.
mnuEditItem(0).Enabled = (txtEdit.SelLength > 0)
mnuEditItem(1).Enabled = (txtEdit.SelLength > 0)
End Sub
Private Sub mnuEditItem_Click(Index As Integer)
Select Case Index
Case 0
' If Index = 0, user chose Cut.
Clipboard.Clear
Clipboard.SetText txtEdit.SelText ' Copy selected text onto the Clipboard.
txtEdit.SelText = "" ' Clear selected text from the document.
Case 1
' If Index = 1, user chose Copy.
Clipboard.Clear
Clipboard.SetText txtEdit.SelText ' Copy selected text onto Clipboard.
Case 2
' If Index = 2, user chose Paste.
txtEdit.SelText = Clipboard.GetText() ' Paste Clipboard text (if any) into document.
End Select
End Sub
Private Sub mnuFileArray_Click(Index As Integer)
' Open the selected file.
If Index >= 0 Then
OpenFile (mnuFileArray(Index).Caption)
End If
End Sub
Private Sub mnuFileItem_Click(Index As Integer)
' CancelError is True
On Error GoTo errhandler
Select Case Index
' Check index value of selected menu item.
Case 0
' If index = 0, the user chose New.
txtEdit.TEXT = "" ' Clear the text box.
Filename = "Untitled" ' Set the title bar caption to "Text Editor: Untitled"
frmEditor.Caption = "Text Editor: " & Filename
Case 1
' If index = 1, the user chose Open.
' Set filters.
CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
' Specify default filter.
CMDialog1.FilterIndex = 2
' Display the File Open dialog box.
CMDialog1.ShowOpen
Filename = CMDialog1.Filename
OpenFile (Filename)
Case 2
' If index = 2, the user chose Save As.
' Set filters.
CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
' Specify default filter.
CMDialog1.FilterIndex = 2
' Display the Save As dialog box.
CMDialog1.ShowSave
Filename = CMDialog1.Filename
CloseFile (Filename)
Case 3
' This menu item is a separator bar, no code needs to be written here
' because it cannot be selected and therefore cannot receive a Click event.
Case 4
' If index = 4, the user chose Exit.
End ' End this application and return to the Windows operating system.
End Select
errhandler:
' The user clicked the Cancel button.
Exit Sub
End Sub
Private Sub mnuFontSizesItem_Click(Index As Integer)
Select Case Index
' Perform an action based on the Index property value of menu control.
Case 0
' If Index = 0, then the user chose font size 12.
txtEdit.FontSize = 12 ' Set the FontSize property of the text box to 12.
mnuFontSizesItem(0).Checked = True ' Display a check mark next to 12.
mnuFontSizesItem(1).Checked = False ' Remove the check mark next to 24.
Case 1
txtEdit.FontSize = 24 ' Set the FontSize property of the text box to 24.
mnuFontSizesItem(0).Checked = False ' Remove the check mark next to 12.
mnuFontSizesItem(1).Checked = True ' Display a check mark next to 24.
End Select
' Display the font size next to the Font Size command.
mnuSettingsItem(1).Caption = Left$(mnuSettingsItem(1).Caption, 10) & " " & mnuFontSizesItem(Index).Caption
End Sub
Private Sub mnuForeColorItem_Click(Index As Integer)
Select Case Index
Case 0
' Set ForeColor to Red
txtEdit.ForeColor = RGB(255, 0, 0)
Case 1
' Set ForeColor to Green
txtEdit.ForeColor = RGB(0, 255, 0)
Case 2
' No code for this case because submenu is automatically displayed in Case 2.
End Select
End Sub
Private Sub tlbToolbar_ButtonClick(ByVal Button As Button)
' CancelError is True
On Error GoTo errhandler
Select Case Button.KEY
Case "New" 'New Button Check
txtEdit.TEXT = "" ' Clear the text box.
Filename = "Untitled" ' Set the title bar caption to "Text Editor: Untitled"
frmEditor.Caption = "Text Editor: " & Filename
Case "Open" 'Open Button Check
' Set filters.
CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
CMDialog1.FilterIndex = 2 ' Specify default filter.
CMDialog1.ShowOpen ' Display the File Open dialog box.
Filename = CMDialog1.Filename
OpenFile (Filename)
Case "SaveAs" 'Save As Button Check
' Set filters.
CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
CMDialog1.FilterIndex = 2 ' Specify default filter.
CMDialog1.ShowSave ' Display the Save As dialog box.
Filename = CMDialog1.Filename
CloseFile (Filename)
Case "Copy" 'Copy Button Check
Clipboard.Clear
Clipboard.SetText txtEdit.SelText ' Copy selected text onto Clipboard.
Case "Cut" 'Cut Button Check
Clipboard.Clear
Clipboard.SetText txtEdit.SelText ' Copy selected text onto the Clipboard.
txtEdit.SelText = "" ' Clear selected text from the document.
Case "Paste" 'Paste Button Check
txtEdit.SelText = Clipboard.GetText() ' Paste Clipboard text (if any) into document.
Case "Bold" 'Bold Button Image Check
txtEdit.Font.Bold = Not txtEdit.Font.Bold
Case "Underline" 'Cut Button Check
txtEdit.Font.Underline = Not txtEdit.Font.Underline
Case "Italics" 'Paste Button Check
txtEdit.Font.Italic = Not txtEdit.Font.Italic
End Select
errhandler:
' The user clicked the Cancel button.
Exit Sub
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -