简体   繁体   中英

gui control that shows current battery level windows mobile C#

I'm looking for a control for Visual Studio that can display the current battery life of windows mobile device. Has anyone come across this before?

Do you know if we can create such a control by ourselves? If so, how?

Create 5 battery icons:

  1. Battery Full
  2. Battery High
  3. Battery Medium
  4. Battery Low
  5. Battery Very Low

using Microsoft.WindowsMobile.Status;

private void UpdateBatteryIcon()
{
    var batteryLevel = SystemState.PowerBatteryStrength;
    var isOnCharge = IsOnCharge(SystemState.PowerBatteryState);
    pictBattery.Image = GetBatteryIcon(batteryLevel, isOnCharge);
}
private static Bitmap GetBatteryIcon(BatteryLevel batteryState, bool isCharging)
{
    if (isCharging)
    {
        return Icons.BatteryChargingHorizontal;
    }
    if (batteryState == BatteryLevel.VeryLow)
    {
        return Icons.BatteryVeryLowHorizontal;
    }
    if (batteryState == BatteryLevel.Low)
    {
        return Icons.BatteryLowHorizontal;
    }
    if (batteryState == BatteryLevel.Medium)
    {
        return Icons.BatteryMediumHorizontal;
    }
    if (batteryState == BatteryLevel.High)
    {
        return Icons.BatteryHighHorizontal;
    }
    return Icons.BatteryFullHorizontal;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM