Find out battery charge capacity in percentage using C# or .NET

后端 未结 9 1511
谎友^
谎友^ 2020-12-03 03:21

I have an application that gets detailed system information, and I have been able to get the percent of charge remaining but not the percent of the battery itself.

E

9条回答
  •  鱼传尺愫
    2020-12-03 03:43

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace batterie
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                showbattrie();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
    
            public void showbattrie()
            {
                PowerStatus status = SystemInformation.PowerStatus;
                textBox1.Text = status.BatteryLifePercent.ToString("P0");
            }
        }
    }
    

提交回复
热议问题