|
-
Nov 19th, 2008, 08:49 PM
#1
Thread Starter
Lively Member
[RESOLVED] Drive space graphic
Hello everyone
I am working on a project and while I can get the free space on a disk, what I would really like to do is to have a graphic from left to right (or bottom to top depending on orentation) that has a picture box (?) and when the program loads, the "slider" (another pic?) covers the bottom pic to indicate the used space for the drive it is on (USB).
E: |XXXXXXXX|___| Kind of like this.
Is this possible? I think I've seen it done on the PortableApps Launcher but it isn't VB.
Any help is very much appreciated.
-
Nov 19th, 2008, 09:54 PM
#2
Re: Drive space graphic
I would think using an API like GetDiskFreeSpaceEx (example provided) would do the trick. Once you know how much is available, how much free & how much is used, calculate percentage used and apply that percentage against the available space for your |xxxxxxxxxx| rectangle.
Then you can use a shape control, solid label to place & position in the picbox. Or, you can simply use the PicBox's Line method to fill in a rectangle:
Picture1.Line (X1,Y1)-(X2,Y2), [color], BF
Last edited by LaVolpe; Nov 19th, 2008 at 10:23 PM.
-
Nov 19th, 2008, 10:33 PM
#3
Re: Drive space graphic
For lighter controls, you can use 2 labels lblDiskSize and lblDiskUsed on the form.
Code:
Option Explicit
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" ( _
ByVal lpRootPathName As String, lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Boolean
'Private Sub UserForm_Initialize() '-- for VBA
Private Sub Form_Load()
Dim BytesFreeToCalller As Currency
Dim TotalBytes As Currency
Dim TotalFreeBytes As Currency
Dim DrivePath As String
'-- can set at design time, make sure that
' lblDiskUsed is in front of lblDiskSize
Me.lblDiskSize.BackColor = vbBlue
Me.lblDiskSize.Width = 150
Me.lblDiskUsed.BackColor = vbRed
Me.lblDiskUsed.Width = 0
Me.lblDiskUsed.Height = Me.lblDiskSize.Height
Me.lblDiskUsed.Left = Me.lblDiskSize.Left
Me.lblDiskUsed.Top = Me.lblDiskSize.Top
'--------------------------------------------
DrivePath = "C:\"
If GetDiskFreeSpaceEx(DrivePath, BytesFreeToCalller, TotalBytes, TotalFreeBytes) Then
Me.lblDiskUsed.Width = Me.lblDiskSize.Width * (1 - TotalFreeBytes / TotalBytes)
Else
Me.lblDiskSize.Width = 0
End If
End Sub
-
Nov 19th, 2008, 11:04 PM
#4
Thread Starter
Lively Member
Re: Drive space graphic
anhn,
That worked perfectly!
One thing I would like to do since it will be on a USB drive is to have it read the drive letter the USB gets, (might be "E" on one pc and "D" on another for example) and display the space for the USB.
Thanks! 
Edit: Found the answer in this thread - http://www.vbforums.com/showthread.p...ht=drive+space
Last edited by Texn; Nov 19th, 2008 at 11:36 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|