4

I've found a number of API's that can help determine how much charge (percentages, charge estimates, etc) - mostly in WMI

in my application, I'd like to know if the computer is currently powered by battery, not the status of the battery. in short, I'd like special behavior when not plugged in

is there such an API? I'm happy with a win32 API to pinvoke if needed

4

2 回答 2

2

尝试这个:-

Boolean x =(System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus == 
       PowerLineStatus.Offline);

还要检查SystemInformation.PowerStatus 属性

于 2013-09-28T18:34:54.333 回答
1

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
}

而已

于 2013-09-28T18:41:24.697 回答