【问题标题】:Checking my laptop battery life by VB.NET通过 VB.NET 检查我的笔记本电脑电池寿命
【发布时间】:2012-04-27 08:52:20
【问题描述】:

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

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

【问题讨论】:

标签: vb.net


【解决方案1】:

你可以试试这个代码

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

【讨论】:

  • 完美运行!对于那些需要一个简单的触发器来包含在他们的应用程序中的人来说,这是一个很好的选择,让用户知道,“伙计,你的电池电量越来越低了。”谢谢你的简单指导!
【解决方案2】:

查看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)

【讨论】:

  • 谢谢!概述了将其集成到他们的应用中所需/使用的所有关键功能。
猜你喜欢
  • 1970-01-01
  • 2012-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-08
  • 1970-01-01
相关资源
最近更新 更多