Results 1 to 4 of 4

Thread: [RESOLVED] Drive space graphic

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Location
    Ft. Worth, Texas
    Posts
    67

    Resolved [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.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Location
    Ft. Worth, Texas
    Posts
    67

    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
  •  



Click Here to Expand Forum to Full Width