/// <summary> /// The event handler used to determine if notifications should be sent to subscribers. /// </summary> private void Timer_Tick(object sender, System.EventArgs e) { // If the end-developer has requested to be notified, check the power status. if (PrimaryBatteryLifeNotification != null) { PowerStatus status = new PowerStatus(); if (this.PrimaryBatteryLifeTrigger == status.BatteryLifePercent) { // Stop the internal timer when the trigger value has been satisfied. It will // be the end-developers responsibility to enable the timer (via this components // Enabled property) to request event notifications again. this.Enabled = false; OnPrimaryBatteryLifeNotification(EventArgs.Empty); } } }
/// <summary> /// The event handler used to determine if notifications should be sent to subscribers. /// </summary> /// <param name="sender">The internal poll timer.</param> /// <param name="e">The EventArgs event data.</param> private void internalTimer_Tick(object sender, EventArgs e) { // There is no point in getting the power status if the end-developer doesn't want to know about it. if (PrimaryBatteryLifeNotification != null) { PowerStatus status = SystemInformationEx.PowerStatus; if (this.primaryBatteryLifeTrigger == status.BatteryLifePercent) { // Stop the internal timer when the trigger value has been satisfied. It will // be the end-developers responsibility to enable the timer (via this components // Enabled property) to request event notification again. Just like he/she would // need to do initially since, by default, Enabled is False. this.pollTimer.Enabled = false; OnPrimaryBatteryLifeNotification(EventArgs.Empty); } } }
/// <summary> /// Initializes a new instance of the BatteryLife class. /// </summary> public BatteryLife() { brushPercentage = new SolidBrush(Color.LightSlateGray); penBorderColor = new Pen(Color.Black); brushStatusBarColor = new SolidBrush(SystemColors.Highlight); if (!onDesktop) { system_power_status_ex = new PowerStatus(); } #if !DESIGN UpdateBatteryLife(); #else // this.SetStyle(ControlStyles.ResizeRedraw, true); // this.UpdateStyles(); //system_power_status_ex.BatteryLifePercent = 75; #endif }
internal static extern bool GetSystemPowerStatusEx2(PowerStatus pStatus, int dwLen, bool fUpdate);
private static extern bool GetSystemPowerStatusEx(PowerStatus pStatus, bool fUpdate);