2

在我的带有框架 2.0 的 VB.Net 项目中,我需要通过编码来获得笔记本电脑或笔记本电脑的当前黄油寿命。

是否可以获得当前的电池状态信息?

4

2 回答 2

11

你可以试试这个代码

Dim power As SystemInformation.PowerStatus = SystemInformation.PowerStatus
Dim percent As Single = power.BatteryLifePercent
MsgBox("Percent battery life remaining: " & percent * 100)
于 2012-04-27T08:59:00.683 回答
8

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

以下代码将为您提供当前的电池信息:

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)
于 2012-04-27T08:56:45.673 回答