我找到了一些API,可以帮助确定电量(百分比、充电估计等),主要是在WMI中。
在我的应用程序中,我想知道计算机当前是否通过电池供电,而不是电池的状态。简而言之,在未连接电源时,我想要特殊的行为。
是否有这样的API?如果需要,我可以使用win32 API进行Pinvoke。
在我的应用程序中,我想知道计算机当前是否通过电池供电,而不是电池的状态。简而言之,在未连接电源时,我想要特殊的行为。
是否有这样的API?如果需要,我可以使用win32 API进行Pinvoke。
试试这个:
Boolean x =(System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus ==
PowerLineStatus.Offline);
。
System.Windows.Forms
命名空间中,有一个 SystemInformation.PowerStatus.BatteryChargeStatus
枚举可以使用:switch (SystemInformation.PowerStatus.BatteryChargeStatus)
{
case BatteryChargeStatus.Charging:
break; //do nothing
default:
//code here. The battery isn't charging so it isn't plugged in
}
就是这样