private void ShowPowerStatus() { PowerStatus status = SystemInformation.PowerStatus; txtChargeStatus.Text = status.BatteryChargeStatus.ToString(); if (status.BatteryFullLifetime == -1) txtFullLifetime.Text = "Unknown"; else txtFullLifetime.Text = status.BatteryFullLifetime.ToString(); txtCharge.Text = status.BatteryLifePercent.ToString("P0"); float battpercent = status.BatteryLifePercent * 100; try { if (battpercent >= float.Parse(txtChargeOff.Text.ToString())) { serialportCommand("off"); } if (battpercent <= float.Parse(txtChargeON.Text)) { serialportCommand("on"); } }catch (Exception ex) { } if (status.BatteryLifeRemaining == -1) txtLifeRemaining.Text = "Unknown"; else txtLifeRemaining.Text = status.BatteryLifeRemaining.ToString(); txtLineStatus.Text = status.PowerLineStatus.ToString(); }