Display Battery Information in VB.NET

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: output 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.
  1.         Dim psBattery As PowerStatus = SystemInformation.PowerStatus
  2.         Dim perFull As Single = psBattery.BatteryLifePercent
Get the Power status that is multiplied by 100.
  1.         If perFull * 100 > 100 Then
  2.             ProgressBar1.Value = 100
  3.         ElseIf perFull * 100 < 100 Then
  4.             ProgressBar1.Value = perFull * 100
  5.         End If
Now, we will get the percentage of the battery and determine if it is charging or not.
  1.         If psBattery.PowerLineStatus = PowerLineStatus.Online Then
  2.             Me.Text = "Battinfo - " & perFull * 100 & "%" & " charging!"
  3.         ElseIf psBattery.PowerLineStatus = PowerLineStatus.Offline Then
  4.             Me.Text = "Battinfo - " & perFull * 100 & "%" & " donĀ“t charging"
  5.         End If
Lastly, just enable the Timer in your Form_Load.
  1.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         Timer1.Enabled = True
  3.     End Sub

Output:

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/BermzISware

Add new comment