📄 frmattribute.frm
字号:
VERSION 5.00
Begin VB.Form frmAttribute
Caption = "属性"
ClientHeight = 2535
ClientLeft = 45
ClientTop = 270
ClientWidth = 2670
LinkTopic = "Form5"
MaxButton = 0 'False
ScaleHeight = 2535
ScaleWidth = 2670
StartUpPosition = 1 '所有者中心
Begin VB.CommandButton cmdCancel
Cancel = -1 'True
Caption = "取消"
Height = 372
Left = 1560
TabIndex = 2
Top = 2040
Width = 855
End
Begin VB.CommandButton cmdOK
Caption = "设定"
Default = -1 'True
Height = 372
Left = 240
TabIndex = 1
Top = 2040
Width = 855
End
Begin VB.Frame Frame1
Caption = "属性列表"
Height = 1695
Left = 120
TabIndex = 0
Top = 120
Width = 2412
Begin VB.CheckBox chkNormal
Caption = "常 规"
Height = 372
Left = 240
TabIndex = 7
Top = 240
Width = 972
End
Begin VB.CheckBox chkReadOnly
Caption = "只 读"
Height = 372
Left = 1320
TabIndex = 6
Top = 240
Width = 972
End
Begin VB.CheckBox chkArchive
Caption = "存 档"
Height = 372
Left = 240
TabIndex = 5
Top = 1200
Width = 972
End
Begin VB.CheckBox chkHidden
Caption = "隐 藏"
Height = 372
Left = 240
TabIndex = 4
Top = 720
Width = 972
End
Begin VB.CheckBox chkSystem
Caption = "系 统"
Height = 372
Left = 1320
TabIndex = 3
Top = 720
Width = 972
End
End
End
Attribute VB_Name = "frmAttribute"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'用来存储文件名属性
Dim msFileName As String
'用来代表文件对象或者文件夹对象
Dim mFileDir
Private Sub cmdOK_Click()
Dim nAttr As Integer
nAttr = 0 '属性变量初始化
'根据复选框的值,来决定文件或者文件夹的属性
If chkNormal.Value = 1 Then nAttr = nAttr + vbNormal
If chkReadOnly.Value = 1 Then nAttr = nAttr + vbReadOnly
If chkHidden.Value = 1 Then nAttr = nAttr + vbHidden
If chkSystem.Value = 1 Then nAttr = nAttr + vbSystem
If chkArchive.Value = 1 Then nAttr = nAttr + vbArchive
'设置文件或者文件夹的属性
mFileDir.Attributes = nAttr
Unload frmAttribute
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Public Property Get FileName() As String
FileName = msFileName
End Property
Public Property Let FileName(ByVal strFile As String)
On Error GoTo errHandler
'给FileName属性赋值
msFileName = strFile
Dim fso As New FileSystemObject
If fso.FolderExists(msFileName) Then
'如果文件名代表的是一个文件夹
Me.Caption = "查看文件夹的属性"
Set mFileDir = fso.GetFolder(msFileName)
ElseIf fso.FileExists(msFileName) Then
'如果文件名代表的是一个文件
Me.Caption = "查看文件的属性"
Set mFileDir = fso.GetFile(msFileName)
Else
'如果文件名即不代表文件夹,也不代表文件,则退出窗体
MsgBox "所指定的文件或者文件夹不存在!", vbCritical, "错误"
Unload Me
End If
'读取被选文件的属性
Dim nAttr As Integer
nAttr = mFileDir.Attributes
'对文件属性作出判断,设置对应的属性检查框
chkNormal.Value = IIf((nAttr And vbNormal) > 0, 1, 0)
chkReadOnly.Value = IIf((nAttr And vbReadOnly) > 0, 1, 0)
chkHidden.Value = IIf((nAttr And vbHidden) > 0, 1, 0)
chkSystem.Value = IIf((nAttr And vbSystem) > 0, 1, 0)
chkArchive.Value = IIf((nAttr And vbArchive) > 0, 1, 0)
Exit Property
errHandler:
MsgBox Err.Description, vbCritical, "错误"
End Property
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -