Finding power source of laptop in c#

Here i am going to write a simple process about how to detect whether your laptop running on battery or current. For this i create a simple windows form application.

A button is placed on the form. I just want to show the system so nothing added without this.

PowerSourceForm

Double click on the button and on its click event write these codes:

private void button1_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”);
}

}

PowerSource

Its done. So simple. Try this.

Fun with code.

Advertisements
  1. #1 by Ramdas Raut on March 7, 2014 - 5:26 am

    It’s Running !!!!!!1 very nice

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: