VB.net电池寿命百分比

VB.net电池寿命百分比,vb.net,percentage,battery,Vb.net,Percentage,Battery,我尝试了很多方法,试图制作一个显示电池百分比的小程序(数值显示在进度条上)。有人能帮我吗 Dim power As SystemInformation.PowerStatus = SystemInformation.PowerStatus Dim percent As Single = power.BatteryLifePercent ' Display the ProgressBar control. pBar1.Visible = true; ' Set min and

我尝试了很多方法,试图制作一个显示电池百分比的小程序(数值显示在进度条上)。有人能帮我吗

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

然后你只需要用定时器或其他东西刷新。

第一次谷歌点击:由于某种原因,它没有像我预期的那样工作。pbar值在1-2左右停止。但是,等一下,在它充满电或显示当前电池百分比之前,还有1-2%的电量?@Andrewenz抱歉,我忘了*100%的数值。我编辑了我的帖子没问题,谢谢:)。我把你的答案标记为最好的。再次感谢