Dieser Artikel wurde maschinell übersetzt. Bewegen Sie den Mauszeiger über die Sätze im Artikel, um den Originaltext anzuzeigen. Weitere Informationen
Übersetzung
Original
Dieser Artikel wurde noch nicht bewertet - Dieses Thema bewerten.

PowerStatus-Klasse

Gibt Informationen über den aktuellen Systemenergiezustand an.

System.Object
  System.Windows.Forms.PowerStatus

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
public class PowerStatus

Der PowerStatus-Typ macht die folgenden Member verfügbar.

  NameBeschreibung
Öffentliche EigenschaftBatteryChargeStatusRuft den aktuellen Akkuladezustand ab.
Öffentliche EigenschaftBatteryFullLifetimeRuft die gemeldete volle Ladungslebensdauer der primären Akkustromquelle in Sekunden ab.
Öffentliche EigenschaftBatteryLifePercentRuft die ungefähre Menge an vollständigem Akkustand ab, die bleibt.
Öffentliche EigenschaftBatteryLifeRemainingRuft die ungefähre verbleibende Akkulebensdauer in Sekunden ab.
Öffentliche EigenschaftPowerLineStatusRuft den aktuellen Systemenergiezustand ab.
Zum Seitenanfang
  NameBeschreibung
Öffentliche MethodeEquals(Object)Bestimmt, ob das angegebene Objekt mit dem aktuellen Objekt identisch ist. (Von Object geerbt.)
Geschützte MethodeFinalize Gibt einem Objekt Gelegenheit, Ressourcen freizugeben und andere Bereinigungen durchzuführen, bevor es von der Garbage Collection freigegeben wird. (Von Object geerbt.)
Öffentliche MethodeGetHashCodeFungiert als Hashfunktion für einen bestimmten Typ. (Von Object geerbt.)
Öffentliche MethodeGetTypeRuft den Type der aktuellen Instanz ab. (Von Object geerbt.)
Geschützte MethodeMemberwiseCloneErstellt eine flache Kopie des aktuellen Object. (Von Object geerbt.)
Öffentliche MethodeToStringGibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt. (Von Object geerbt.)
Zum Seitenanfang

Die PowerStatus-Klasse stellt Informationen über den aktuellen Zustand der Netzstromversorgung, der Akkuladung und und des Akkuladevorgangs dar.

Die PowerStatus-Eigenschaft der SystemInformation-Klasse gibt mithilfe dieser Klasse Informationen über den aktuellen Systemenergiezustand an.

Im folgenden Beispiel werden alle Eigenschaften der PowerStatus-Klasse in einem ListBox-Steuerelement aufgeführt, und bei der Auswahl eines Listenelements wird der aktuelle Wert der zugeordneten Eigenschaft in einem TextBox-Steuerelement angezeigt.


using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;

namespace PowerStatusBrowser
{
    public class PowerStatusBrowserForm : System.Windows.Forms.Form
    {
        private System.Windows.Forms.ListBox listBox1;
        private System.Windows.Forms.TextBox textBox1;        

        public PowerStatusBrowserForm()
        {
            this.SuspendLayout();
            InitForm();

            //Add each property of the PowerStatus class to the list box.
            Type t = typeof(System.Windows.Forms.PowerStatus);            
            PropertyInfo[] pi = t.GetProperties();            
            for( int i=0; i<pi.Length; i++ )
                listBox1.Items.Add( pi[i].Name );            
            textBox1.Text = "The PowerStatus class has "+pi.Length.ToString()+" properties.\r\n";

            // Configure the list item selected handler for the list box to invoke a 
            // method that displays the value of each property.           
            listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged);
            this.ResumeLayout(false);
        }
		
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Return if no item is selected.
            if( listBox1.SelectedIndex == -1 ) return;
            // Get the property name from the list item
            string propname = listBox1.Text;

            // Display the value of the selected property of the PowerStatus type.
            Type t = typeof(System.Windows.Forms.PowerStatus);
            PropertyInfo[] pi = t.GetProperties();            
            PropertyInfo prop = null;
            for( int i=0; i<pi.Length; i++ )
                if( pi[i].Name == propname )
                {
                    prop = pi[i];
                    break;           
                }

            object propval = prop.GetValue(SystemInformation.PowerStatus, null);            
            textBox1.Text += "\r\nThe value of the "+propname+" property is: "+propval.ToString();
        }

        private void InitForm()
        {
            // Initialize the form settings
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.textBox1 = new System.Windows.Forms.TextBox();            
            this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
            this.listBox1.Location = new System.Drawing.Point(8, 16);
            this.listBox1.Size = new System.Drawing.Size(172, 496);
            this.listBox1.TabIndex = 0;            
            this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                | System.Windows.Forms.AnchorStyles.Right)));
            this.textBox1.Location = new System.Drawing.Point(188, 16);
            this.textBox1.Multiline = true;
            this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;           
            this.textBox1.Size = new System.Drawing.Size(420, 496);
            this.textBox1.TabIndex = 1;            
            this.ClientSize = new System.Drawing.Size(616, 525);            
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.listBox1);            
            this.Text = "Select a PowerStatus property to get the value of";                   
        }

        [STAThread]
        static void Main() 
        {
            Application.Run(new PowerStatusBrowserForm());
        }
    }
}


.NET Framework

Unterstützt in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Unterstützt in: 4, 3.5 SP1

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core-Rolle wird nicht unterstützt), Windows Server 2008 R2 (Server Core-Rolle wird mit SP1 oder höher unterstützt; Itanium wird nicht unterstützt)

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.
Alle öffentlichen static (Shared in Visual Basic)-Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.
Fanden Sie dies hilfreich?
(1500 verbleibende Zeichen)

Community-Beiträge

HINZUFÜGEN
© 2013 Microsoft. Alle Rechte vorbehalten.