protected virtual void OnBatteryStateChanged(BatteryEventArgs e) { BatteryStateChanged.Raise(this, e); Logging.LoggingManager.LogEvent(Logging.LogEventType.DEBUG, "BatteryState changed: " + e.BatteryState); if(e.ChargingState == ChargingState.OnBattery) Logging.LoggingManager.LogEvent(Logging.LogEventType.DEBUG, "Battery remaining: " + e.BatteryRemaining); }
private void OnBatteryStateChanged(object sender, BatteryEventArgs e) { UpdateStatusBarBatteryState(e.BatteryState); // TODO: might want to save this state and compare to save time UpdateBatteryToolTipText(e.BatteryRemaining); }
private void UpdateBatteryState() { bool isChargingNow = (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online); // TODO: PowerLineStatus.Unknown wird nicht behandelt |f| würde es so lassen short batteryStateNow = (short)Math.Floor(SystemInformation.PowerStatus.BatteryLifePercent * 100f); int batteryRemaining = SystemInformation.PowerStatus.BatteryLifeRemaining; if (_isCharging != isChargingNow || _batteryState != batteryStateNow || batteryRemaining != _batteryRemaining) { BatteryEventArgs args = new BatteryEventArgs() { BatteryState = CalculateBatteryState(batteryStateNow), ChargingState = CalculateChargingState(isChargingNow), BatteryRemaining = CalculateBatteryRemaining(batteryRemaining) }; OnBatteryStateChanged(args); _isCharging = isChargingNow; _batteryState = batteryStateNow; _batteryRemaining = batteryRemaining; } }