16,553
社区成员
发帖
与我相关
我的任务
分享
Public Sub ReadDisk()
Dim ct As Integer = 0, i As Integer
On Error Resume Next
Dim cts As String = Nothing
ct = comboBox1.SelectedIndex
For Each Mydrv As DriveInfo In Mydriver
If Mydrv.IsReady Then
Arry(j, 0) = Mydrv.Name '盘符
Arry(j, 1) = "磁盘名称:" & Mydrv.VolumeLabel '卷标
Arry(j, 2) = "磁盘格式:" & Mydrv.DriveFormat '磁盘格式
Dim ALLdisk As Double = Format(Val(Mydrv.TotalSize.ToString / (1024 * 1024 * 1024)) / 1024, "Fixed")
Dim FreDisk As Double = Format(Val(Mydrv.TotalFreeSpace.ToString / (1024 * 1024 * 1024)) / 1024, "Fixed")
Arry(j, 3) = "磁盘容量:" & ALLdisk & "TB" '总大小
Arry(j, 4) = "磁盘剩余:" & FreDisk & "TB" '剩余大小
Arry(j, 5) = "磁盘使用:" & ALLdisk - FreDisk & "TB" '使用大小
j += 1
End If
Next
For i = 1 To 5
If i = 1 Then
cts = Arry(ct, i)
Else
cts = cts & vbCrLf & Arry(ct, i)
End If
Next
label1.Text = cts
Dim Maxin = Val(Microsoft.VisualBasic.Mid(Arry(ct, 3), 6, Len(Arry(ct, 3)) - 7))
Dim Valt = Val(Microsoft.VisualBasic.Mid(Arry(ct, 5), 6, Len(Arry(ct, 5)) - 7))
Dim Iuy As Integer = (Valt / Maxin) * 100
Label2.Text = Iuy & "%"
Label3.Text = 100 - Iuy & "%"
panel2.Width = panel1.Width * (Iuy / 100)
Label2.Left = (panel2.Width - Label2.Width) * 0.5
Label3.Left = (panel1.Width + panel2.Width) * 0.5 - Label3.Width * 0.5
End Sub
这个是我写的读取磁盘的代码,但是好像不能时时读取。。。郁闷