How to get the current battery level in C#
By Anuraj P on February 8th, 2012 . 2 Comments .
Today I found one blogpost related to how to get laptop battery level. But it was using WMI, and it was slow. Then after searching in MSDN, I found PowerStatus class, which is part of System.Windows.Forms namespace, which can be used to get the battery level. Here is a simple implementation, which shows battery status as well as system connected to AC power.
And here is the code snippet.
PowerStatus p = SystemInformation.PowerStatus;
progressBar1.Value = (int)(p.BatteryLifePercent * 100);
label1.Text = string.Format("{0}%", (p.BatteryLifePercent * 100));
radioButton1.Checked = p.PowerLineStatus == PowerLineStatus.Online;
radioButton2.Checked = p.PowerLineStatus == PowerLineStatus.Offline;
radioButton3.Checked = p.PowerLineStatus == PowerLineStatus.Unknown;
And here is the application running on my laptop

Current Battery Status
Happy Coding
2 Responses to “How to get the current battery level in C#”
RSS feed for comments on this post. TrackBack URL
[...] Today I found one blogpost related to how to get laptop battery level. But it was using WMI, and it was slow. Then after searching in MSDN, I found PowerStatus class, which is part of System.Windows.Forms namespace, which can be … Continue reading → .NET Read the original post on Dot Net Thoughts… [...]
Pingback by How to get the current battery level in C# | .NET | Syngu — February 8, 2012 @ 11:42 pm
wowww that is very informative!!!keep it up!
Comment by Mehreen — May 10, 2012 @ 1:40 pm