如何从笔记本电脑的电池中读取电池充电量的信息 [英] How to read the battery charge\backup information from a laptop's battery

查看:296
本文介绍了如何从笔记本电脑的电池中读取电池充电量的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我需要创建一个程序来从笔记本电脑的电池中读取电池电量\ backup信息

Here i need to create a program to read the battery charge\backup information from a laptop's battery

推荐答案

好的,我保留了你的最后一个问题假设是真的一个但不是,你在这里看起来像家庭作业问题的系列。 :doh:



很抱歉,这里没有快速提问。这看起来像你的大学任务,你应该付出一些努力。



我们希望你花一些时间来尝试你所面临的问题然后在制定时间发布在这里的问题。我看到他们都失踪了。 :doh:



以下是询问者的预期:

1. 首先尝试你想要什么做!

2.制定你所做的看似问题/不工作的事情。



尝试一下,告诉你是否面对问题。

各位会员非常乐意为此提供帮助。
Ok, I left your last question assuming a genuine one but no, you are here with series that looks like a homework questions. :doh:

I am sorry but there is no quick question here. This looks like your college assignment, you should put some effort.

We expect you to put some time in trying the issue that you are facing and then some time in formulating the question while posting here. I see both missing. :doh:

Here is what is expected by enquirers:
1. TRY first what you want to do!
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.


Dictionary<uint16,> StatusCodes;private void Form1_Load(object sender, EventArgs e)
        {
            StatusCodes = new Dictionary<ushort,>();
            StatusCodes.Add(1, "The battery is discharging");
            StatusCodes.Add(2, "The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging");
            StatusCodes.Add(3, "Fully Charged");
            StatusCodes.Add(4, "Low");
            StatusCodes.Add(5, "Critical");
            StatusCodes.Add(6, "Charging");
            StatusCodes.Add(7, "Charging and High");
            StatusCodes.Add(8, "Charging and Low");
            StatusCodes.Add(9, "Undefined");
            StatusCodes.Add(10,"Partially Charged");/* Set progress bar values and Properties */progressBar1.Maximum = 100;
            progressBar1.Style = ProgressBarStyle.Continuous;
 
 
            timer1.Enabled = true;
 
            ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_Battery");foreach (ManagementObject mo in mos.Get())
            {
                lblBatteryName.Text = mo["Name"].ToString();
                UInt16 statuscode = (UInt16)mo["BatteryStatus"];string statusString = StatusCodes[statuscode];
                lblBatteryStatus.Text = statusString;
            }
        }private void timer1_Tick(object sender, EventArgs e)
        {
            ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_Battery where Name='"+lblBatteryName.Text+"'");foreach (ManagementObject mo in mos.Get())
            {
 
                UInt16 statuscode = (UInt16)mo["BatteryStatus"];string statusString = StatusCodes[statuscode];
                lblBatteryStatus.Text = statusString;/* Set Progress bar according to status  */if (statuscode == 4)
                {
                    progressBar1.ForeColor = Color.Red;
                    progressBar1.Value = 5;
                }else if (statuscode == 3)
                {
                    progressBar1.ForeColor = Color.Blue;
                    progressBar1.Value = 100;
                }else if (statuscode == 2)
                {
                    progressBar1.ForeColor = Color.Green;
                    progressBar1.Value = 100;
                }else if (statuscode == 5)
                {
                    progressBar1.ForeColor = Color.Red;
                    progressBar1.Value = 1;
                }else if (statuscode == 6)
                {
                    progressBar1.ForeColor = Color.Blue;
                    progressBar1.Value = 100;
                }
            }
}


这篇关于如何从笔记本电脑的电池中读取电池充电量的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆