2012-04-27 180 views
2

在我的VB.Net項目與框架2.0,我需要通過編碼獲得筆記本電腦或筆記本電腦當前的黃油壽命。用VB.NET檢查我的筆記本電腦電池壽命

可以獲取當前的電池狀態信息嗎?

+0

這裏是現成的代碼 - http://syntaxhelp.com/VB.NET/Retrieve - 電池 - 信息 – 2012-04-27 08:57:29

回答

9

你可以試試這個代碼

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

查看SystemInformation類,更具體地說,PowerStatus屬性(它返回PowerStatus class的實例)。

下面的代碼會給你當前的電池信息:

Dim powerstatus As PowerStatus = SystemInformation.PowerStatus 

' Gets the current battery charge status. 
MessageBox.Show("BatteryChargeStatus : " & powerstatus.BatteryChargeStatus) 

' Gets the reported full charge lifetime of the primary battery power source in seconds. 
MessageBox.Show("BatteryFullLifetime : " & powerstatus.BatteryFullLifetime) 

' Gets the approximate amount of full battery charge remaining. 
MessageBox.Show("BatteryLifePercent : " & powerstatus.BatteryLifePercent) 

' Gets the approximate number of seconds of battery time remaining. 
MessageBox.Show("BatteryLifeRemaining : " & powerstatus.BatteryLifeRemaining) 

' Gets the current system power status. 
MessageBox.Show("PowerLineStatus : " & powerstatus.PowerLineStatus) 
相關問題