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

📄 form1.frm

📁 vb精彩编程希望大家有用
💻 FRM
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1 
   Caption         =   "文件操作"
   ClientHeight    =   5070
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6525
   LinkTopic       =   "Form1"
   ScaleHeight     =   5070
   ScaleWidth      =   6525
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command2 
      Caption         =   "保存文件"
      Height          =   495
      Left            =   4800
      TabIndex        =   2
      Top             =   1200
      Width           =   1455
   End
   Begin VB.CommandButton Command1 
      Caption         =   "打开文件"
      Height          =   495
      Left            =   4800
      TabIndex        =   1
      Top             =   480
      Width           =   1455
   End
   Begin MSComDlg.CommonDialog cd1 
      Left            =   5040
      Top             =   2400
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.TextBox Text1 
      Height          =   4815
      Left            =   120
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   0
      Text            =   "Form1.frx":0000
      Top             =   120
      Width           =   4455
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim modi As Boolean  '记录文本框中的内容是否修改
Dim filename As String  '保存已打开的文件名
Private Sub Command1_Click()
    If modi Then
        If MsgBox("数据已被修改还未保存,真的新建文件?", vbYesNo, "提示") = vbNo Then Exit Sub
    End If
    Dim fso As New FileSystemObject
    Dim f
    Dim ts As TextStream
    cd1.DialogTitle = "打开文件"
    cd1.Filter = "文本文件(*.txt) |*.txt| 所有文件 (*.*) | *.*"
    cd1.ShowOpen
    filename = cd1.filename
    Set f = fso.GetFile(filename)
    Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
    Text1.Text = ts.ReadAll
    ts.Close
    Set ts = Nothing
    Set f = Nothing
    Set fso = Nothing
    Text1.SetFocus
End Sub
Private Sub Command2_Click()
    If modi = True Then
        Dim fso, f
        Set fso = CreateObject("scripting.filesystemobject")
        fso.CreateTextFile filename
        Set f = fso.GetFile(filename)
        Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
        ts.Write Text1.Text
        ts.Close
        modi = False
    End If
End Sub
Private Sub Form_Load()
    modi = False
End Sub
Private Sub Text1_Change()
    modi = True
End Sub

⌨️ 快捷键说明

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