Code of showing the Battery Information in
Advertisement
VB.NET
Advertisement
Let’s starts with the source code of VB.NET in which we try to show the information of battery.
Advertisement
Form1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 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 Timer1.Interval = 30000 End Sub End Class |
Form1.Designer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class Form1 Inherits System.Windows.Forms.Form 'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then components.Dispose() End If Finally MyBase.Dispose(disposing) End Try End Sub 'Wird vom Windows Form-Designer benötigt. Private components As System.ComponentModel.IContainer 'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich. 'Das Bearbeiten ist mit dem Windows Form-Designer möglich. 'Das Bearbeiten mit dem Code-Editor ist nicht möglich. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container Me.ProgressBar1 = New System.Windows.Forms.ProgressBar Me.Timer1 = New System.Windows.Forms.Timer(Me.components) Me.SuspendLayout() ' 'ProgressBar1 ' Me.ProgressBar1.Dock = System.Windows.Forms.DockStyle.Fill Me.ProgressBar1.Location = New System.Drawing.Point(0, 0) Me.ProgressBar1.Name = "ProgressBar1" Me.ProgressBar1.Size = New System.Drawing.Size(219, 22) Me.ProgressBar1.Step = 1 Me.ProgressBar1.Style = System.Windows.Forms.ProgressBarStyle.Continuous Me.ProgressBar1.TabIndex = 4 ' 'Timer1 ' Me.Timer1.Interval = 1 ' 'Form1 ' Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None Me.ClientSize = New System.Drawing.Size(219, 22) Me.Controls.Add(Me.ProgressBar1) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow Me.MaximizeBox = False Me.MinimizeBox = False Me.Name = "Form1" Me.ShowIcon = False Me.ShowInTaskbar = False Me.Text = "Battinfo" Me.TopMost = True Me.ResumeLayout(False) End Sub Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar Friend WithEvents Timer1 As System.Windows.Forms.Timer End Class |
Download VB.NET Code to show Battery Information