?? edit.frm
字號:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmEditor
Caption = "記事本: Untitled"
ClientHeight = 4020
ClientLeft = 1425
ClientTop = 1650
ClientWidth = 5580
ClipControls = 0 'False
Icon = "edit.frx":0000
LinkTopic = "Form2"
PaletteMode = 1 'UseZOrder
ScaleHeight = 3753.867
ScaleMode = 0 'User
ScaleWidth = 5580
Begin VB.TextBox txtEdit
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 4020
Left = 0
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 0
Width = 5565
End
Begin MSComDlg.CommonDialog CMDialog1
Left = 840
Top = 1680
_ExtentX = 847
_ExtentY = 847
_Version = 393216
CancelError = -1 'True
End
Begin VB.Menu mnuFile
Caption = "文件[&F]"
Begin VB.Menu mnuFileItem
Caption = "新建[&N]"
Index = 0
Shortcut = ^N
End
Begin VB.Menu mnuFileItem
Caption = "打開[&O]"
Index = 1
Shortcut = ^O
End
Begin VB.Menu mnuFileItem
Caption = "保存[&S]"
Index = 2
Shortcut = ^S
End
Begin VB.Menu mnuFileItem
Caption = "另存為"
Index = 3
End
Begin VB.Menu mnuFileItem
Caption = "-"
Index = 4
End
Begin VB.Menu mnuFileItem
Caption = "退出[&Q]"
Index = 5
Shortcut = ^Q
End
Begin VB.Menu mnuFileArray
Caption = "-"
Index = 0
Visible = 0 'False
End
End
Begin VB.Menu mnuEdit
Caption = "編輯[&E]"
Begin VB.Menu mnuEditItem
Caption = "剪切[&X]"
Index = 0
Shortcut = ^X
End
Begin VB.Menu mnuEditItem
Caption = "復制[&C]"
Index = 1
Shortcut = ^C
End
Begin VB.Menu mnuEditItem
Caption = "粘貼[&V]"
Index = 2
Shortcut = ^V
End
End
Begin VB.Menu mnuSettings
Caption = "設置[&S]"
Begin VB.Menu mnuSettingsItem
Caption = "顏色"
Index = 0
Begin VB.Menu mnuColorsItem
Caption = "背景色"
Index = 0
Begin VB.Menu mnuBackColorItem
Caption = "紅"
Index = 0
End
Begin VB.Menu mnuBackColorItem
Caption = "綠"
Index = 1
End
Begin VB.Menu mnuBackColorItem
Caption = "藍"
Index = 2
End
End
Begin VB.Menu mnuColorsItem
Caption = "前景色"
Index = 1
Begin VB.Menu mnuForeColorItem
Caption = "紅"
Index = 0
End
Begin VB.Menu mnuForeColorItem
Caption = "綠"
Index = 1
End
Begin VB.Menu mnuForeColorItem
Caption = "藍"
Index = 2
Begin VB.Menu mnuBlueItem
Caption = "淡藍"
Index = 0
End
Begin VB.Menu mnuBlueItem
Caption = "深藍"
Index = 1
Begin VB.Menu mnuDarkBlueItem
Caption = "海藍"
Index = 0
End
Begin VB.Menu mnuDarkBlueItem
Caption = "墨藍"
Index = 1
End
End
End
End
End
Begin VB.Menu mnuSettingsItem
Caption = "字體大小"
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
End
Attribute VB_Name = "frmEditor"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
' 設置當前路徑
ChDir App.Path
ChDrive App.Path
' 設置文本框的位置
txtEdit.Move 0, 0
' 初始Filename變量
Filename = "Untitled"
' 設置窗體位置
Top = Screen.Height / 2 - Height / 2
Left = Screen.Width / 2 - Width / 2
End Sub
Private Sub Form_Resize()
' 窗體大小改變時,相應的改變文本框大小
txtEdit.Width = ScaleWidth
txtEdit.Height = ScaleHeight
End Sub
Private Sub mnuBackColorItem_Click(Index As Integer)
Select Case Index
Case 0 ' 設置背景色為紅色
txtEdit.BackColor = RGB(255, 0, 0)
Case 1 ' 設置背景色為綠色
txtEdit.BackColor = RGB(0, 255, 0)
Case 2 ' 設置背景色為藍色
txtEdit.BackColor = RGB(0, 0, 255)
End Select
End Sub
Private Sub mnuBlueItem_Click(Index As Integer)
' 如果用戶選擇淡藍,設置前景色
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
' 設置前景色為海藍
txtEdit.ForeColor = RGB(0, 50, 175)
Case 1
' 設置前景色為墨藍
txtEdit.ForeColor = RGB(0, 0, 255)
End Select
End Sub
Private Sub mnuEdit_Click()
' 如果沒有選中文本則使剪切和復制不可用
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
' 如果 Index = 0, 剪切選中文本
Clipboard.Clear
Clipboard.SetText txtEdit.SelText ' 剪切選擇的文本到Clipboard中.
txtEdit.SelText = "" ' 清除選中的文本
Case 1
' 如果 Index = 1, 復制選中文本
Clipboard.Clear
Clipboard.SetText txtEdit.SelText ' 復制選擇的文本到Clipboard中
Case 2
' 如果 Index = 2, 粘貼文本
txtEdit.SelText = Clipboard.GetText() ' 粘貼文本
End Select
End Sub
Private Sub mnuFileArray_Click(Index As Integer)
' 打開選擇的文件
If Index >= 0 Then
OpenFile (mnuFileArray(Index).Caption)
End If
End Sub
Private Sub mnuFileItem_Click(Index As Integer)
On Error GoTo errhandler
Select Case Index
' 根據(jù)菜單的索引選擇相應的操作
Case 0
' 如果index = 0, 新建文本文件
txtEdit.Text = "" '清空文本框內容
Filename = "Untitled"
frmEditor.Caption = "記事本: " & Filename '設置記事本標題為 "記事本: Untitled"
Case 1
' 如果index = 1, 打開文本文件
' 設置過濾器
CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
' 設置缺省過濾器
CMDialog1.FilterIndex = 2
' 顯示"打開"對話框
CMDialog1.ShowOpen
Filename = CMDialog1.Filename
OpenFile (Filename)
Case 2
' 如果index = 2, 保存文件
' 設置過濾器
CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
' 設置缺省過濾器
CMDialog1.FilterIndex = 2
If Filename = "Untitled" Then
'如果文件尚未命名,則顯示保存對話框
CMDialog1.ShowSave
Filename = CMDialog1.Filename
CloseFile (Filename)
Else
'否則直接保存
SaveFile (Filename)
End If
Case 3
' 如果index = 3,另存文件
' 設置過濾器
CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
' 設置缺省過濾器
CMDialog1.FilterIndex = 2
' 顯示另存對話框
CMDialog1.ShowSave
Filename = CMDialog1.Filename
CloseFile (Filename)
Case 4
' 無操作,分隔
Case 5
' 如果index = 5, 退出程序
End
End Select
errhandler:
' 錯誤處理
Exit Sub
End Sub
Private Sub mnuFontSizesItem_Click(Index As Integer)
Select Case Index
' 根據(jù)菜單選項設置字體大小
Case 0
' 如果 Index = 0, 字體大小為12
txtEdit.FontSize = 12
mnuFontSizesItem(0).Checked = True
mnuFontSizesItem(1).Checked = False
' 如果 Index = 1, 字體大小為24
Case 1
txtEdit.FontSize = 24
mnuFontSizesItem(0).Checked = False
mnuFontSizesItem(1).Checked = True
End Select
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
' 設置前景色為紅色
txtEdit.ForeColor = RGB(255, 0, 0)
Case 1
' 設置前景色為綠色
txtEdit.ForeColor = RGB(0, 255, 0)
Case 2
' 藍色子菜單
End Select
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -