Win CE 5.0 increases battery power display

Source: Internet
Author: User

Excerpted from http://blog.csdn.net/li0531/article/details/8818243

A Label control is displayed only in the upper-right corner, so the amount of code is reduced a lot.

[DllImport ("Coredll")]Private Static extern intGetsystempowerstatusex (SYSTEM_POWER_STATUS_EX Lpsystempowerstatus,BOOLfupdate); [DllImport ("Coredll")] Public Static extern voidSystemidletimerreset ();PrivateSYSTEM_POWER_STATUS_EX STATUS =NewSYSTEM_POWER_STATUS_EX ();/// <summary>  /////Whether the charge status///// </summary>  //private state astate = State.normal;/// <summary>  ///Battery current status Charge: charging; Undercharge: low power; normal: battery is in use. /// </summary>   Public enumstate{/// <summary>      ///in charge/// </summary>  Charge,/// <summary>      ///Insufficient charge/// </summary>  Undercharge,/// <summary>      ///Normal State/// </summary>  Normal,/// <summary>      ///Charging Complete/// </summary>  chargefinally};Private classsystem_power_status_ex{ Public byteACLineStatus =0;  Public byteBatteryflag =0;  Public byteBatteryLifePercent =0;  Public byteReserved1 =0;  Public UINTBatterylifetime =0;  Public UINTBatteryFullLifetime =0;  Public byteReserved2 =0;  Public byteBackupbatteryflag =0;  Public byteBackupbatterylifepercent =0;  Public byteRESERVED3 =0;  Public UINTBackupbatterylifetime =0;  Public UINTBackupbatteryfulllifetime =0;}/// <summary>///To create a power indicator/// </summary>Private voidgetbatterystate () {if(Getsystempowerstatusex (Status,false) ==1)    {        if(Status. BatteryLifePercent >= the) {Labbattery.text=" -"; Labbattery.forecolor=Color.green; }        Else if(Status. BatteryLifePercent <= -)        {            if(Status. ACLineStatus = =1) Labbattery.text= status. Batterylifepercent.tostring () +" +"; ElseLabbattery.text="! "+status.            Batterylifepercent.tostring (); Labbattery.forecolor=color.red; }        Else{Labbattery.text= status. Batterylifepercent.tostring () + (status. ACLineStatus = =1?" +":""); Labbattery.forecolor=Color.Blue; }    }}

I call this method at a frequency of 10m under the Timer control.

Win CE 5.0 increases battery power display

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.