Search code examples
vb.netpercentagebattery

VB.net battery life percentage


I tried many methods trying to make a small programs which shows the battery percentage (the value is displayed on a progressbar).Can anyone help me?


Solution

  • Dim power As SystemInformation.PowerStatus = SystemInformation.PowerStatus
    Dim percent As Single = power.BatteryLifePercent    
    
    ' Display the ProgressBar control.
        pBar1.Visible = true;
    
    ' Set min and max
        pBar1.Minimum = 0
        pBar1.Maximum = 100
    
    ' Set the current value 
        pBar1.Value = percent * 100
    

    Then you just need to refresh with a timer or something else.