Display Battery Information in VB.NET
Submitted by donbermoy on Wednesday, June 3, 2015 - 23:58.
This tutorial will teach you how to create a program that will get the information of the battery of your laptop such as getting its percentage battery and if it is charging or not using vb.net language.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Next, add only one ProgressBar on the Form and a Timer on it. Design like this:
3. Now, let's do the coding.
We will first code for the Tick Event of the Timer.
Declare first the variables for the System Information of the Power Status.
Get the Power status that is multiplied by 100.
Now, we will get the percentage of the battery and determine if it is charging or not.
Lastly, just enable the Timer in your Form_Load.
- Dim psBattery As PowerStatus = SystemInformation.PowerStatus
- Dim perFull As Single = psBattery.BatteryLifePercent
- If perFull * 100 > 100 Then
- ProgressBar1.Value = 100
- ElseIf perFull * 100 < 100 Then
- ProgressBar1.Value = perFull * 100
- End If
- If psBattery.PowerLineStatus = PowerLineStatus.Online Then
- Me.Text = "Battinfo - " & perFull * 100 & "%" & " charging!"
- ElseIf psBattery.PowerLineStatus = PowerLineStatus.Offline Then
- Me.Text = "Battinfo - " & perFull * 100 & "%" & " donĀ“t charging"
- End If
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Timer1.Enabled = True
- End Sub
Output:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:donbermoy@engineer.com Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISwareAdd new comment
- 1231 views