0

I am working on VB.NET windows mobile application, in visual studio 2005. I want to check my device battery charge so I given code my form load like this:

Imports System.IO 
Imports System.Data 
Imports System.Drawing.Imaging 
Imports System.Configuration 
Imports Microsoft.Win32 
Imports System.Windows.Forms 
Imports Microsoft.VisualBasic 
Imports System 

Dim power As SystemInformation.PowerStatus = SystemInformation.PowerStatus
Dim percent As Single = power.BatteryLifePercent
MsgBox("Percent battery life remaining: " & percent * 100)

But showing error

SystemInformation.PowerStatus is not defined.

Any one tell me how I can resolve this issue

user3697824
  • 538
  • 4
  • 15
jas jas
  • 25
  • 3
  • 14
  • Visual Studio **2005**? Do you mean *2015*? Do you have a reference to `System.Windows.Forms` in your project? And the appropriate `Imports` statement? – Tim Feb 17 '16 at 06:23
  • yes sir,i wam working in visual studio 2005. Imports System.io Imports System.Data Imports System.Drawing.Imaging Imports System.Configuration Imports Microsoft.Win32 Imports System.Windows.Forms Imports Microsoft.VisualBasic Imports system – jas jas Feb 17 '16 at 06:29
  • i added this much imports – jas jas Feb 17 '16 at 06:29
  • dear @tim sir ,any idea what i can do? – jas jas Feb 17 '16 at 06:50
  • any one have any idea? how i can resolve this issue.. – jas jas Feb 17 '16 at 08:07

2 Answers2

0

Forget the guys talking about VS2015. This is not related to compact framwework running on your windows mobile device!

you need to use the state and notification api: in c# this is

using Microsoft.WindowsMobile.Status; // see https://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.status.aspx
...
BatteryLevel batteryLevel = SystemState.PowerBatteryStrength;
BatteryState batteryState = SystemState.PowerBatteryState;

ensure you are on target Windows Mobile 6.x! and comapct framework 3.5

Another approach would be to use P/Invoke and GetSystemPowerStatusEx. see How do you get the current battery level in .NET CF 3.5?

If you do not install and target at least the Windows Mobile 6 SDK you will not see Microsoft.WindowsMobile.Status in add References.

If you want to stay with PPC2003, you need to use the P/Invoke for GetSystemPowerStatusEx.

Here is a nice artcile about getting Battery Status, if you understand this. There are many other sites, don't be lazy and use your internet search engine.

And sorry, but as MS renames there SDKs and re-arranges web sites without looking at existing links, even on there pages and search results, I was unable to find the Developer Toolkit (DTK) for Windows Mobile 6.5 (which has been renamed to Windows Embedded Handheld 6.5).

Community
  • 1
  • 1
josef
  • 5,951
  • 1
  • 13
  • 24
  • i am not able to download Microsoft.WindowsMobile.Status ..without adding this into refernce i cannot import this right? – jas jas Feb 18 '16 at 07:30
  • sir i can able to see Target device :Pocket PC 2003 SE Emulator – jas jas Feb 18 '16 at 08:03
  • PocketPC 2003 is very outdated and does not have WindowsMobile.Status. Please install at least Windows Mobile 6 SDK or use pinvoke with the native function GetSystemPowerStatusEx – josef Mar 17 '16 at 06:02
-1

PowerStatus when used to declare the type of a variable part of System.Windows.Forms, not SystemInformation. The line

Dim power As SystemInformation.PowerStatus = SystemInformation.PowerStatus

needs to be changed to:

Dim power As System.Windows.Forms.PowerStatus = SystemInformation.PowerStatus

This worked for me (I'm in Visual Studio 2013, but that shouldn't make a difference).

Private Sub ShowBatteryPercent()
    Dim power As System.Windows.Forms.PowerStatus = SystemInformation.PowerStatus
    Dim percent As Single = power.BatteryLifePercent
    MsgBox("Percent battery life remaining: " & percent * 100)
End Sub

Must make sure you have Imports System.Windows.Forms.

RianBattle
  • 898
  • 6
  • 20
  • sir i have Imports System.Windows.Forms but while using this code i am getting error System.Windows.Forms.PowerStatus is not defined – jas jas Feb 17 '16 at 16:06
  • i am working on visual studio 2005 and developing application for widnows mobile device center,i want to show battery status of device – jas jas Feb 17 '16 at 16:07
  • I don't believe the version of visual studio should matter. Do you have `System.Windows.Forms` listed in your project references also? What version of .NET framework are you developing for? – RianBattle Feb 17 '16 at 16:20
  • sir i can able to see Target device :Pocket PC 2003 SE Emulator – jas jas Feb 17 '16 at 16:34
  • In Visual studio 2005 i think .net frame work 2 is using – jas jas Feb 17 '16 at 16:38
  • this answer is not suitable for COMPACT FRAMEWORK – josef Feb 18 '16 at 05:44