📄 frmedit.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
Begin VB.Form frmEdit
Caption = "Document - Text Editor"
ClientHeight = 4590
ClientLeft = 165
ClientTop = 735
ClientWidth = 6030
LinkTopic = "Form1"
ScaleHeight = 4590
ScaleWidth = 6030
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox txtEdit
Height = 855
Left = 0
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 0
Top = 0
Width = 1215
End
Begin MSComDlg.CommonDialog dlgEdit
Left = 2640
Top = 2400
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.Menu mnuFile
Caption = "&File"
Begin VB.Menu mnuFileNew
Caption = "&New"
Shortcut = ^N
End
Begin VB.Menu mnuFileOpen
Caption = "&Open..."
Shortcut = ^O
End
Begin VB.Menu Hyphen1
Caption = "-"
End
Begin VB.Menu mnuFileSave
Caption = "&Save"
Shortcut = ^S
End
Begin VB.Menu mnuFileSaveAs
Caption = "Save &As..."
Shortcut = ^A
End
Begin VB.Menu Hyphen2
Caption = "-"
End
Begin VB.Menu mnuFilePrint
Caption = "&Print..."
Shortcut = ^P
End
Begin VB.Menu Hyphen3
Caption = "-"
End
Begin VB.Menu mnuFileExit
Caption = "E&xit"
End
End
Begin VB.Menu mnuEdit
Caption = "&Edit"
Begin VB.Menu mnuEditCut
Caption = "Cu&t"
Shortcut = ^X
End
Begin VB.Menu mnuEditCopy
Caption = "&Copy"
Shortcut = ^C
End
Begin VB.Menu mnuEditPaste
Caption = "&Paste"
Shortcut = ^V
End
Begin VB.Menu Hyphen4
Caption = "-"
End
Begin VB.Menu mnuEditFind
Caption = "&Find..."
Shortcut = ^F
End
Begin VB.Menu mnuEditFindNext
Caption = "Find &Next"
Shortcut = {F3}
End
End
End
Attribute VB_Name = "frmEdit"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim strSearchFor As String
Dim blnChange As Boolean, blnCancelsave As Boolean
Private Sub Form_Load()
blnChange = False
blnCancelsave = False
End Sub
Private Sub Form_Resize()
txtEdit.Height = frmEdit.ScaleHeight
txtEdit.Width = frmEdit.ScaleWidth
End Sub
Private Sub Form_Unload(Cancel As Integer)
Const conBtns As Integer = vbYesNoCancel + vbExclamation _
+ vbDefaultButton3 + vbApplicationModal
Const conMsg As String = "Do you want to save the current document?"
Dim intUserResponse As Integer
If blnChange = True Then 'document was changed since last save
intUserResponse = MsgBox(conMsg, conBtns, "Editor")
Select Case intUserResponse
Case vbYes 'user wants to save current document
Call mnuFileSave_Click
If blnCancelsave = True Then 'user canceled save
Cancel = 1 'return to document-don't unload form
End If
Case vbNo 'user does not want to save current document
'unload form and exit
Case vbCancel
Cancel = 1 'return to document-don't unload form
End Select
End If
End Sub
Private Sub mnuEdit_Click()
If txtEdit.SelText = "" Then
mnuEditCut.Enabled = False
mnuEditCopy.Enabled = False
Else
mnuEditCut.Enabled = True
mnuEditCopy.Enabled = True
End If
If Clipboard.GetText() = "" Then
mnuEditPaste.Enabled = False
Else
mnuEditPaste.Enabled = True
End If
End Sub
Private Sub mnuEditCopy_Click()
Clipboard.Clear 'clear clipboard
Clipboard.SetText txtEdit.SelText 'send text to clipboard
End Sub
Private Sub mnuEditCut_Click()
Clipboard.Clear 'clear clipboard
Clipboard.SetText txtEdit.SelText 'send text to clipboard
txtEdit.SelText = "" 'remove selected text from text box
End Sub
Private Sub mnuEditFind_Click()
Const conBtns As Integer = vbOKOnly + vbInformation _
+ vbDefaultButton1 + vbApplicationModal
Const conMsg As String = "The search string was not found."
Dim intRetVal As Integer
Dim intFoundPos As Integer
strSearchFor = InputBox("Find what?", "Find") 'prompt user for text
intFoundPos = InStr(1, txtEdit.Text, strSearchFor, 1) 'search for text
If intFoundPos = 0 Then 'if text was not found
intRetVal = MsgBox(conMsg, conBtns, "Find")
Else 'if text was found
txtEdit.SelStart = intFoundPos - 1 'highlight text
txtEdit.SelLength = Len(strSearchFor)
End If
End Sub
Private Sub mnuEditFindNext_Click()
Const conBtns As Integer = vbOKOnly + vbInformation _
+ vbDefaultButton1 + vbApplicationModal
Const conMsg As String = "The search has been completed."
Dim inRetVal As Integer
Dim intFoundPos As Integer, intBegSearch As Integer
intBegSearch = txtEdit.SelStart + 2
intFoundPos = InStr(intBegSearch, txtEdit.Text, strSearchFor, 1)
If intFoundPos = 0 Then 'if text was not found
inRetVal = MsgBox(conMsg, conBtns, "Find Next")
Else 'if text was found
txtEdit.SelStart = intFoundPos - 1 'highlight text
txtEdit.SelLength = Len(strSearchFor)
End If
End Sub
Private Sub mnuEditPaste_Click()
'retrieve text from clipboard and paste into text box
txtEdit.SelText = Clipboard.GetText()
End Sub
Private Sub mnuFileExit_Click()
Unload frmEdit
End Sub
Private Sub mnuFileNew_Click()
Const conBtns As Integer = vbYesNoCancel + vbExclamation _
+ vbDefaultButton3 + vbApplicationModal
Const conMsg As String = "Do you want to save the current document?"
Dim intUserResponse As Integer
If blnChange = True Then 'text box was changed since last save
intUserResponse = MsgBox(conMsg, conBtns, "Editor")
Select Case intUserResponse
Case vbYes 'user wants to save current file
Call mnuFileSave_Click
If blnCancelsave = True Then
Exit Sub
End If
Case vbNo 'user does not want to save current file
Case vbCancel 'user wants to cancel New command
Exit Sub
End Select
End If
txtEdit.Text = "" 'clear text box
blnChange = False 'reset variable
frmEdit.Caption = "Document - Text Editor"
dlgEdit.FileName = ""
End Sub
Private Sub mnuFileOpen_Click()
Const conBtns As Integer = vbYesNoCancel + vbExclamation _
+ vbDefaultButton3 + vbApplicationModal
Const conMsg As String = "Do you want to save the current document?"
Dim intUserResponse As Integer
On Error GoTo OpenErrHandler
dlgEdit.CancelError = True
If blnChange = True Then 'document was changed since last save
intUserResponse = MsgBox(conMsg, conBtns, "Editor")
Select Case intUserResponse
Case vbYes 'user wants to save current document
Call mnuFileSave_Click
If blnCancelsave = True Then 'user canceled save
Exit Sub
End If
Case vbNo 'user doesn't want to save current document
'process instructions below End If
Case vbCancel 'user wants to cancel Open command
Exit Sub
End Select
End If
dlgEdit.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
dlgEdit.FileName = ""
dlgEdit.ShowOpen
Open dlgEdit.FileName For Input As 1
txtEdit.Text = Input(LOF(1), 1)
Close #1
blnChange = False
frmEdit.Caption = dlgEdit.FileName & " - Text Editor"
Exit Sub
OpenErrHandler:
End Sub
Private Sub mnuFileSave_Click()
If frmEdit.Caption = "Document - Text Editor" Then
Call mnuFileSaveAs_Click 'new document
Else 'existing document
Open dlgEdit.FileName For Output As #1
Print #1, txtEdit.Text
Close #1
blnChange = False
End If
End Sub
Private Sub mnuFileSaveAs_Click()
On Error GoTo SaveErrHandler
dlgEdit.CancelError = True
dlgEdit.Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
dlgEdit.Filter = "Text Files(*.txt)|*.txt"
dlgEdit.ShowSave
Open dlgEdit.FileName For Output As #1
Print #1, txtEdit.Text
Close #1
frmEdit.Caption = dlgEdit.FileName & "-Text Editor"
blnChange = False
blnCancelsave = False
Exit Sub
SaveErrHandler:
blnCancelsave = True
End Sub
Private Sub txtEdit_Change()
blnChange = True
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -