2016-05-13 210 views
-3

我尝试了很多方法来尝试制作一个显示电池电量百分比的小程序(值显示在进度条上)。任何人都可以帮助我吗?VB.net电池使用时间百分比

+2

首先谷歌命中:['PowerStatus.BatteryLifePercent'](https://msdn.microsoft.com/en-us/library/system.windows.forms.powerstatus.batterylifepercent(v = vs.110).aspx) –

回答

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 

然后,你只需要刷新一个计时器或别的东西。

+0

出于某种原因,它不能按我的预期工作.Pbar值停在大约1-2。但是等待,剩下1-2%,直到完全充电或显示当前电池的百分比? –

+0

@AndrewHenz对不起,我忘了* 100的百分比值。我编辑了我的帖子 – nbadaud

+0

没问题,谢谢:)。我标记你的答案是最好的。再次感谢 –