Click here to Skip to main content
16,006,535 members
Home / Discussions / C#
   

C#

 
GeneralRe: Illegal Cross Thread Opperation Pin
eggie511-Sep-04 17:41
eggie511-Sep-04 17:41 
GeneralTrackBar in a ToolStrip Pin
eggie511-Sep-04 10:31
eggie511-Sep-04 10:31 
GeneralCapturing Window, I got C++ code - please help! Pin
nantcom11-Sep-04 8:21
nantcom11-Sep-04 8:21 
GeneralRe: Capturing Window, I got C++ code - please help! Pin
Nick Parker11-Sep-04 10:05
protectorNick Parker11-Sep-04 10:05 
GeneralRe: Capturing Window, I got C++ code - please help! Pin
nantcom11-Sep-04 19:20
nantcom11-Sep-04 19:20 
GeneralFound the way! Pin
nantcom11-Sep-04 22:10
nantcom11-Sep-04 22:10 
GeneralBattery status in c# Pin
nocture11-Sep-04 6:43
nocture11-Sep-04 6:43 
GeneralRe: Battery status in c# Pin
Nick Parker11-Sep-04 7:26
protectorNick Parker11-Sep-04 7:26 
Try something like the following:

[DllImport("Kernel32")]
private static extern Boolean GetSystemPowerStatus(SystemPowerStatus sps);
[StructLayout(LayoutKind.Sequential)]
public class SystemPowerStatus
{
        public ACLineStatus _ACLineStatus;
        public BatteryFlag  _BatteryFlag;
        public Byte         _BatteryLifePercent;
        public Byte         _Reserved1;
        public Int32        _BatteryLifeTime;
        public Int32        _BatteryFullLifeTime;
}

public enum ACLineStatus : byte
{
    Offline = 0, Online = 1, Unknown = 255
}

public enum BatteryFlag : byte
{
        High = 1,
        Low = 2,
        Critical = 4,
        Charging = 8,
        NoSystemBattery = 128,
        Unknown = 255
}


Your usage would look like this for example:
private void button1_Click(object sender, EventArgs e)
{
    SystemPowerStatus sps = new SystemPowerStatus();
    GetSystemPowerStatus(sps);
    if (sps != null)
    {
        MessageBox.Show(string.Format("Current battery life is at {0}%.", sps._BatteryLifePercent));
    }
}


- Nick Parker
My Blog | My Articles

GeneralRe: Battery status in c# Pin
nocture11-Sep-04 7:53
nocture11-Sep-04 7:53 
GeneralRe: Battery status in c# Pin
Nick Parker11-Sep-04 8:15
protectorNick Parker11-Sep-04 8:15 
GeneralRe: Battery status in c# Pin
nocture11-Sep-04 8:29
nocture11-Sep-04 8:29 
GeneralListView DisplayMember Pin
eggie511-Sep-04 4:46
eggie511-Sep-04 4:46 
GeneralRe: ListView DisplayMember Pin
Baris Kurtlutepe11-Sep-04 8:04
Baris Kurtlutepe11-Sep-04 8:04 
GeneralRe: ListView DisplayMember Pin
eggie511-Sep-04 10:29
eggie511-Sep-04 10:29 
GeneralHelp with XML Pin
krisst_k10-Sep-04 23:31
krisst_k10-Sep-04 23:31 
GeneralRe: Help with XML Pin
Anonymous10-Sep-04 23:33
Anonymous10-Sep-04 23:33 
GeneralConverting Keys to Chars Pin
User 12301610-Sep-04 23:25
User 12301610-Sep-04 23:25 
GeneralRe: Converting Keys to Chars Pin
EssOEss11-Sep-04 1:10
EssOEss11-Sep-04 1:10 
GeneralRe: Converting Keys to Chars Pin
User 12301612-Sep-04 10:30
User 12301612-Sep-04 10:30 
GeneralFinally Pin
User 12301612-Sep-04 22:45
User 12301612-Sep-04 22:45 
GeneralRemote FileExists problem Pin
DougW4810-Sep-04 20:47
DougW4810-Sep-04 20:47 
GeneralRe: Remote FileExists problem Pin
Salil Khedkar13-Sep-04 1:41
Salil Khedkar13-Sep-04 1:41 
GeneralRe: Remote FileExists problem Pin
DougW4813-Sep-04 17:41
DougW4813-Sep-04 17:41 
GeneralUpdown control in C# Pin
thatsqlguy10-Sep-04 20:44
thatsqlguy10-Sep-04 20:44 
Generalcustom object serializing Pin
akbar nasrabadi10-Sep-04 20:30
akbar nasrabadi10-Sep-04 20:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.