⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editplus.frm

📁 VB6程序设计参考手册 -独立源码 VB6程序设计参考手册 -独立源码
💻 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 frmEditor 
   Caption         =   "记事本: Untitled"
   ClientHeight    =   4020
   ClientLeft      =   1425
   ClientTop       =   1650
   ClientWidth     =   5580
   ClipControls    =   0   'False
   Icon            =   "editPlus.frx":0000
   LinkTopic       =   "Form2"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   3753.867
   ScaleMode       =   0  'User
   ScaleWidth      =   5580
   Begin RichTextLib.RichTextBox txtEdit 
      Height          =   3735
      Left            =   120
      TabIndex        =   0
      Top             =   240
      Width           =   5295
      _ExtentX        =   9340
      _ExtentY        =   6588
      _Version        =   393217
      HideSelection   =   0   'False
      ScrollBars      =   3
      TextRTF         =   $"editPlus.frx":0442
   End
   Begin MSComDlg.CommonDialog CMDialog1 
      Left            =   3840
      Top             =   0
      _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
      Begin VB.Menu mnuEditItem 
         Caption         =   "-"
         Index           =   3
      End
      Begin VB.Menu mnuEditItem 
         Caption         =   "查找"
         Index           =   4
         Shortcut        =   ^F
      End
      Begin VB.Menu mnuEditItem 
         Caption         =   "替换"
         Index           =   5
         Shortcut        =   ^E
      End
      Begin VB.Menu mnuEditItem 
         Caption         =   "-"
         Index           =   6
      End
      Begin VB.Menu mnuEditItem 
         Caption         =   "全选"
         Index           =   7
         Shortcut        =   ^A
      End
   End
   Begin VB.Menu mnuSettings 
      Caption         =   "设置[&S]"
      Begin VB.Menu mnuSettingsItem 
         Caption         =   "字体"
         Index           =   0
      End
      Begin VB.Menu mnuSettingsItem 
         Caption         =   "颜色"
         Index           =   1
      End
   End
   Begin VB.Menu mnuHelp 
      Caption         =   "帮助[&H]"
      Begin VB.Menu mnuHelpItem 
         Caption         =   "显示帮助"
         Index           =   0
      End
      Begin VB.Menu mnuHelpItem 
         Caption         =   "-"
         Index           =   1
      End
      Begin VB.Menu mnuHelpItem 
         Caption         =   "关于"
         Index           =   2
      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"
    FileType = 1

    ' 设置窗体位置
    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 mnuFileItem_Click(Index As Integer)
      
    On Error GoTo errhandler
    
    ' 设置过滤器
    CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|RTF Files (*.rtf)|*.rtf"
    ' 设置缺省过滤器
    CMDialog1.FilterIndex = 2
    Select Case Index
        ' 根据菜单的索引选择相应的操作
        Case 0
            ' 如果index = 0, 新建文本文件
            txtEdit.Text = ""               '清空文本框内容
            FileName = "Untitled"
            frmEditor.Caption = "记事本: " & FileName  '设置记事本标题为 "记事本: Untitled"
        Case 1
            ' 如果index = 1, 打开文本文件
            ' 显示"打开"对话框
            CMDialog1.ShowOpen
            FileName = CMDialog1.FileName
            OpenFile (FileName)
        Case 2
            ' 如果index = 2, 保存文件
            If FileName = "Untitled" Then
                '如果文件尚未命名,则显示保存对话框
                CMDialog1.ShowSave
                FileName = CMDialog1.FileName
                WriteFile (FileName)
            Else
                '否则直接保存
                SaveFile (FileName)
            End If
        Case 3
            ' 如果index = 3,另存文件
            ' 显示另存对话框
            CMDialog1.ShowSave
            FileName = CMDialog1.FileName
            WriteFile (FileName)
        Case 4
            ' 无操作,分隔
        Case 5
            End
    End Select
errhandler:
        ' 错误处理
        Exit Sub
End Sub

'  “文件”菜单中的历史文件列表菜单
Private Sub mnuFileArray_Click(Index As Integer)
    
    ' 打开选择的文件
    If Index >= 0 Then
        OpenFile (mnuFileArray(Index).Caption)
    End If

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
            If FileType = 0 Then            ' 剪切选择的文本到Clipboard中.
                Clipboard.SetText txtEdit.SelRTF
                txtEdit.SelRTF = ""         ' 清除选中的文本
            Else
                Clipboard.SetText txtEdit.SelText
                txtEdit.SelText = ""        ' 清除选中的文本
            End If
        Case 1
            ' 如果 Index = 1, 复制选中文本
            Clipboard.Clear
            If FileType = 0 Then     ' 复制选择的文本到Clipboard中
                Clipboard.SetText txtEdit.SelRTF
            Else
                Clipboard.SetText txtEdit.SelText
            End If
        Case 2
            ' 如果 Index = 2, 粘贴文本
            txtEdit.SelText = Clipboard.GetText()   ' 粘贴文本
        Case 3
            ' 菜单分隔符
        Case 4, 5
            ' 如果 Index = 4 5, 查找 替换
            frmFind.Show 0, frmEditor
        Case 6
            ' 菜单分隔符
        Case 7
            ' 如果 Index = 4, 全选
            txtEdit.SelStart = 0
            txtEdit.SelLength = Len(txtEdit.Text)
    End Select
    
End Sub

'  “设置”菜单
Private Sub mnuSettingsItem_Click(Index As Integer)
    On Error GoTo errhandler
    Select Case Index
    Case 0
    '  设置字体
        CMDialog1.Flags = cdlCFBoth
        CMDialog1.ShowFont   '显示“字体”对话框
        With txtEdit
            .SelFontName = CMDialog1.FontName
            .SelBold = CMDialog1.FontBold
            .SelItalic = CMDialog1.FontItalic
            .SelFontSize = CMDialog1.FontSize
            .SelUnderline = CMDialog1.FontUnderline
            .SelStrikeThru = CMDialog1.FontStrikethru
        End With
    Case 1
    '  设置字体颜色
        CMDialog1.ShowColor '显示“颜色”对话框
        txtEdit.SelColor = CMDialog1.Color
    End Select
errhandler:
        ' 错误处理
        Exit Sub
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -