form1.frm

来自「很好的教程原代码!」· FRM 代码 · 共 101 行

FRM
101
字号
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1 
   Caption         =   "用CommonDialog打开多个文件"
   ClientHeight    =   2775
   ClientLeft      =   1515
   ClientTop       =   2280
   ClientWidth     =   5670
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   ScaleHeight     =   2775
   ScaleWidth      =   5670
   Begin VB.CommandButton Command2 
      Caption         =   "退    出"
      Height          =   324
      Left            =   3432
      TabIndex        =   3
      Top             =   2352
      Width           =   1428
   End
   Begin VB.CommandButton Command1 
      Caption         =   "选择文件"
      Height          =   324
      Left            =   792
      TabIndex        =   0
      Top             =   2352
      Width           =   1428
   End
   Begin VB.ListBox List1 
      Height          =   1680
      Left            =   144
      TabIndex        =   1
      Top             =   360
      Width           =   5340
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   2016
      Top             =   0
      _ExtentX        =   688
      _ExtentY        =   688
      _Version        =   393216
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "选择的文件:"
      Height          =   180
      Left            =   144
      TabIndex        =   2
      Top             =   72
      Width           =   1080
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_Click()
    
    Dim DlgInfo As DlgFileInfo
    Dim I As Integer
    
    On Error GoTo ErrHandle
    
    '清除List1中的项
    List1.Clear
    
    '选择文件
    With CommonDialog1
        .CancelError = True
        .MaxFileSize = 32767 '被打开的文件名尺寸设置为最大,即32K
        .Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks
        .DialogTitle = "选择文件"
        .Filter = "所有类型的文件(*.*)|*.*"
        .ShowOpen
        DlgInfo = GetDlgSelectFileInfo(.FileName)
        .FileName = ""      '在打开了*.pif文件后须将Filename属性置空,
                            '否则当选取多个*.pif文件后,当前路径会改变
    End With
    
    For I = 1 To DlgInfo.iCount
        List1.AddItem DlgInfo.sPath & DlgInfo.sFile(I)
    Next I
    
    Exit Sub

ErrHandle:
' 按了“取消”按钮

End Sub



Private Sub Command2_Click()
    End
End Sub


⌨️ 快捷键说明

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