开发者

gui control that shows current battery level windows mobile C#

开发者 https://www.devze.com 2023-03-06 04:43 出处:网络
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?

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消