2012-04-27 78 views
2

在我的VB.Net项目与框架2.0,我需要通过编码获得笔记本电脑或笔记本电脑当前的黄油寿命。用VB.NET检查我的笔记本电脑电池寿命

可以获取当前的电池状态信息吗?

+0

这里是现成的代码 - http://syntaxhelp.com/VB.NET/Retrieve - 电池 - 信息 – 2012-04-27 08:57:29

回答

9

你可以试试这个代码

Dim power As SystemInformation.PowerStatus = SystemInformation.PowerStatus 
Dim percent As Single = power.BatteryLifePercent 
MsgBox("Percent battery life remaining: " & percent * 100) 
6

查看SystemInformation类,更具体地说,PowerStatus属性(它返回PowerStatus class的实例)。

下面的代码会给你当前的电池信息:

Dim powerstatus As PowerStatus = SystemInformation.PowerStatus 

' Gets the current battery charge status. 
MessageBox.Show("BatteryChargeStatus : " & powerstatus.BatteryChargeStatus) 

' Gets the reported full charge lifetime of the primary battery power source in seconds. 
MessageBox.Show("BatteryFullLifetime : " & powerstatus.BatteryFullLifetime) 

' Gets the approximate amount of full battery charge remaining. 
MessageBox.Show("BatteryLifePercent : " & powerstatus.BatteryLifePercent) 

' Gets the approximate number of seconds of battery time remaining. 
MessageBox.Show("BatteryLifeRemaining : " & powerstatus.BatteryLifeRemaining) 

' Gets the current system power status. 
MessageBox.Show("PowerLineStatus : " & powerstatus.PowerLineStatus) 
相关问题