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:
- Battery Full
- Battery High
- Battery Medium
- Battery Low
- 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;
}
精彩评论