在c#中访问系统计费的命名空间是什么 [英] what is the namespace to access system charging in c#

查看:70
本文介绍了在c#中访问系统计费的命名空间是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在c#中访问系统计费的命名空间是什么,或者我如何操作系统计费

what is the namespace to access system charging in c#, or how can i manipulate system charging

推荐答案

请检查以下链接。



这是电池健康状况的解决方案,可在堆栈溢出中找到。

http://stackoverflow.com/questions/8945986/find-out-battery-status-in-c-sharp-or-net [ ^ ]



请检查 win32_Battery Class。我不太了解它。

您可以参考MSDN文档,

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394074%28v=vs.85 %29.aspx [ ^ ]



请找到复制的代码,我想它会回答你的问题。

我试过这个代码,它对我来说很好。



Please check the following links.

This is solution for battery health, found in stack overflow.
http://stackoverflow.com/questions/8945986/find-out-battery-status-in-c-sharp-or-net[^]

Please check win32_Battery Class. I don't know more about it.
You may please refer the MSDN documentation for that,
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394074%28v=vs.85%29.aspx[^]

Please find copied the code, i think it will answer your question.
I tried this code and its working fine for me.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using Microsoft.Win32;

namespace WpfSample
{
    public partial class MainWindow : Window
    {
 
        public MainWindow()
        {
            InitializeComponent();
            SystemEvents.PowerModeChanged += new
                   PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
        }
 
       void SystemEvents_PowerModeChanged(object sender, 
                                                   PowerModeChangedEventArgs e)
       {
     switch (System.Windows.Forms.SystemInformation.PowerStatus.BatteryChargeStatus)
                {
                case System.Windows.Forms.BatteryChargeStatus.Low:
                        MessageBox.Show("Battery is running low.", "Low Battery");
                       break;
                case System.Windows.Forms.BatteryChargeStatus.Critical:
                       MessageBox.Show("Battery is critcal", "Critical Battery");
                       break;             
                case System.Windows.Forms.BatteryChargeStatus.Charging:
                       MessageBox.Show("Battery is Charging.", "Charging Battery");
                       break;
                case System.Windows.Forms.BatteryChargeStatus.High:
                       MessageBox.Show("Battery is Good.", "High Battery");
                       break;
                case System.Windows.Forms.BatteryChargeStatus.NoSystemBattery:
                       MessageBox.Show("Battery not found.", "Battery Not found");
                       break;
                case System.Windows.Forms.BatteryChargeStatus.Unknown:
                       MessageBox.Show("Battery status unknown.", "Unknown");
                       break;
               }
         }
    }

}


这篇关于在c#中访问系统计费的命名空间是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆