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

📄 edit.frm

📁 VB6程序设计参考手册的独立源码
💻 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
            ' 根据菜单的索引选择相应的操作
            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
        ' 根据菜单选项设置字体大小
            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 + -