Here’s some code to programmatically find out if your laptop is currently running on battery power. I have created a Windows Form application and added the following code on a button click event which uses the SystemInformation.PowerStatus property
C#
private void btnPower_Click(object sender, EventArgs e)
{
PowerLineStatus status = SystemInformation.PowerStatus.PowerLineStatus;
if (status == PowerLineStatus.Offline)
MessageBox.Show("Running on Battery");
else
MessageBox.Show("Running on Power");
}
VB.NET (Converted Code)
Private Sub btnPower_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim st As PowerLineStatus = SystemInformation.PowerStatus.PowerLineStatus
If st = PowerLineStatus.Offline Then
MessageBox.Show("Running on Battery")
Else
MessageBox.Show("Running on Power")
End If
End Sub
Tweet
1 comment:
How to find what device running a application?
Example
If i running a application in desktop or laptop or tablet or mobile devices
Post a Comment