gui控件显示当前电池电量windows mobile C#

时间:2011-05-15 06:37:27

标签: c# windows-mobile controls power-management

我正在寻找可以显示Windows移动设备当前电池寿命的Visual Studio控件。有没有人遇到过这个?

你知道我们是否可以自己创造这样的控制吗?如果是这样,怎么样?

1 个答案:

答案 0 :(得分:1)

创建5个电池图标:

  1. 电池已满
  2. 电池电量高
  3. 电池介质
  4. 电池电压低
  5. 电池电量非常低
  6. 使用Microsoft.WindowsMo​​bile.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;
    }