Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Here i need to create a program to read the battery charge\backup information from a laptop's battery
Posted

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.
 
Share this answer
 
v2
C#
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;
                }
            }
}
 
Share this answer
 
v2
Comments
Toli Cuturicu 18-Mar-11 20:24pm    
Really, can't you use <pre lang="cs"></pre> tags or are you plain lazy?
What about proper indenting...? Someone may want to actually read your answer!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900