-3

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?

  • 2
    First google hit: [`PowerStatus.BatteryLifePercent`](https://msdn.microsoft.com/en-us/library/system.windows.forms.powerstatus.batterylifepercent(v=vs.110).aspx) – Tim Schmelter May 13 '16 at 12:39

1 Answers1

1
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.

nbadaud
  • 694
  • 7
  • 26
  • For some reason it's not working as I expected.The pbar value stops at about 1-2.But wait,there is 1-2% left until it's fully charged or it shows the current battery percentage? – Andrew Henz May 13 '16 at 13:10
  • @AndrewHenz Sorry, i forgot to *100 the percent value. I edited my post – nbadaud May 13 '16 at 13:28
  • No problem,thanks :) .I marked your answer as being the best.And thanks again – Andrew Henz May 13 '16 at 13:47