我正在寻找可以显示Windows移动设备当前电池寿命的Visual Studio控件。有没有人遇到过这个?
你知道我们是否可以自己创造这样的控制吗?如果是这样,怎么样?
答案 0 :(得分:1)
创建5个电池图标:
使用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;
}