/// <summary> /// 秀出電量百分比 /// </summary> /// <returns></returns> public string ShowPercent() { _SYSTEM_POWER_STATUS SystemPower = new _SYSTEM_POWER_STATUS(); GetSystemPowerStatus(ref SystemPower); string BatteryLifePercent = $@"電量:{Convert.ToString(SystemPower.BatteryLifePercent)}%{" / "}"; var status = Convert.ToString(SystemPower.ACLineStatus); string ACLineStatus = ""; switch (status) { case "0": ACLineStatus = ""; //未充電 break; case "1": ACLineStatus = "充電中"; break; default: ACLineStatus = "查無充電裝置"; //查無充電裝置 break; } ACLineStatus += ACLineStatus == "" ? "" : " / "; return($@"{BatteryLifePercent}{ACLineStatus}"); }
public static void ShowInfo() { _SYSTEM_POWER_STATUS SystemPower = new _SYSTEM_POWER_STATUS(); GetSystemPowerStatus(ref SystemPower); MessageBox.Show("電力供電狀態:" + Convert.ToString(SystemPower.ACLineStatus) + "\n" + "估計剩餘時間:" + Convert.ToString(SystemPower.BatteryLifeTime) + " seconds. \n" + "估計電力剩餘:" + Convert.ToString(SystemPower.BatteryLifePercent) + "% \n"); }
private static extern void GetSystemPowerStatus(ref _SYSTEM_POWER_STATUS systemPowerStatus);