SystemInformation 類別

定義

提供目前系統環境的相關資訊。

public ref class SystemInformation
public ref class SystemInformation abstract sealed
public class SystemInformation
public static class SystemInformation
type SystemInformation = class
Public Class SystemInformation
繼承
SystemInformation

範例

下列程式碼範例會列出 中 ListBox 類別的所有屬性 SystemInformation ,並在選取清單專案時,在 中 TextBox 顯示 屬性的目前值。

#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::Drawing;
using namespace System::Reflection;
using namespace System::Windows::Forms;
public ref class SystemInfoBrowserForm: public System::Windows::Forms::Form
{
private:
   System::Windows::Forms::ListBox^ listBox1;
   System::Windows::Forms::TextBox^ textBox1;

public:
   SystemInfoBrowserForm()
   {
      this->SuspendLayout();
      InitForm();
      
      // Add each property of the SystemInformation class to the list box.
      Type^ t = System::Windows::Forms::SystemInformation::typeid;
      array<PropertyInfo^>^pi = t->GetProperties();
      for ( int i = 0; i < pi->Length; i++ )
         listBox1->Items->Add( pi[ i ]->Name );
      textBox1->Text = String::Format( "The SystemInformation class has {0} properties.\r\n", pi->Length );
      
      // Configure the list item selected handler for the list box to invoke a 
      // method that displays the value of each property.
      listBox1->SelectedIndexChanged += gcnew EventHandler( this, &SystemInfoBrowserForm::listBox1_SelectedIndexChanged );
      this->ResumeLayout( false );
   }


private:
   void listBox1_SelectedIndexChanged( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      
      // Return if no list item is selected.
      if ( listBox1->SelectedIndex == -1 )
            return;

      
      // Get the property name from the list item.
      String^ propname = listBox1->Text;
      if ( propname->Equals( "PowerStatus" ) )
      {
         
         // Cycle and display the values of each property of the PowerStatus property.
         textBox1->Text = String::Concat( textBox1->Text, "\r\nThe value of the PowerStatus property is:" );
         Type^ t = System::Windows::Forms::PowerStatus::typeid;
         array<PropertyInfo^>^pi = t->GetProperties();
         for ( int i = 0; i < pi->Length; i++ )
         {
            Object^ propval = pi[ i ]->GetValue( SystemInformation::PowerStatus, nullptr );
            textBox1->Text = String::Format( "{0}\r\n    PowerStatus.{1} is: {2}", textBox1->Text, pi[ i ]->Name, propval );

         }
      }
      else
      {
         
         // Display the value of the selected property of the SystemInformation type.
         Type^ t = System::Windows::Forms::SystemInformation::typeid;
         array<PropertyInfo^>^pi = t->GetProperties();
         PropertyInfo^ prop = nullptr;
         for ( int i = 0; i < pi->Length; i++ )
            if ( pi[ i ]->Name == propname )
            {
               prop = pi[ i ];
               break;
            }
         Object^ propval = prop->GetValue( nullptr, nullptr );
         textBox1->Text = String::Format( "{0}\r\nThe value of the {1} property is: {2}", textBox1->Text, propname, propval );
      }
   }

   void InitForm()
   {
      
      // Initialize the form settings
      this->listBox1 = gcnew System::Windows::Forms::ListBox;
      this->textBox1 = gcnew 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 = System::Drawing::Point( 8, 16 );
      this->listBox1->Size = 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 = System::Drawing::Point( 188, 16 );
      this->textBox1->Multiline = true;
      this->textBox1->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
      this->textBox1->Size = System::Drawing::Size( 420, 496 );
      this->textBox1->TabIndex = 1;
      this->ClientSize = System::Drawing::Size( 616, 525 );
      this->Controls->Add( this->textBox1 );
      this->Controls->Add( this->listBox1 );
      this->Text = "Select a SystemInformation property to get the value of";
   }

};


[STAThread]
int main()
{
   Application::Run( gcnew SystemInfoBrowserForm );
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;

namespace SystemInfoBrowser
{
    public class SystemInfoBrowserForm : System.Windows.Forms.Form
    {
        private System.Windows.Forms.ListBox listBox1;
        private System.Windows.Forms.TextBox textBox1;        
        
        public SystemInfoBrowserForm()
        {
            this.SuspendLayout();
            InitForm();
            
            // Add each property of the SystemInformation class to the list box.
            Type t = typeof(System.Windows.Forms.SystemInformation);            
            PropertyInfo[] pi = t.GetProperties();            
            for( int i=0; i<pi.Length; i++ )
                listBox1.Items.Add( pi[i].Name );            
            textBox1.Text = "The SystemInformation 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 list item is selected.
            if( listBox1.SelectedIndex == -1 ) return;
            // Get the property name from the list item.
            string propname = listBox1.Text;
            
            if( propname == "PowerStatus" )
            {
                // Cycle and display the values of each property of the PowerStatus property.
                textBox1.Text += "\r\nThe value of the PowerStatus property is:";                                
                Type t = typeof(System.Windows.Forms.PowerStatus);
                PropertyInfo[] pi = t.GetProperties();            
                for( int i=0; i<pi.Length; i++ )
                {
                    object propval = pi[i].GetValue(SystemInformation.PowerStatus, null);            
                    textBox1.Text += "\r\n    PowerStatus."+pi[i].Name+" is: "+propval.ToString();
                }
            }
            else
            {
                // Display the value of the selected property of the SystemInformation type.
                Type t = typeof(System.Windows.Forms.SystemInformation);
                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(null, 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 SystemInformation property to get the value of";                   
        }

        [STAThread]
        static void Main() 
        {
            Application.Run(new SystemInfoBrowserForm());
        }
    }
}
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Reflection
Imports System.Windows.Forms

Public Class SystemInfoBrowserForm
    Inherits System.Windows.Forms.Form
    
    Private listBox1 As System.Windows.Forms.ListBox
    Private textBox1 As System.Windows.Forms.TextBox  
    
    Public Sub New()
        Me.SuspendLayout()
        InitForm()
        
        ' Add each property of the SystemInformation class to the list box.
        Dim t As Type = GetType(System.Windows.Forms.SystemInformation)
        Dim pi As PropertyInfo() = t.GetProperties()
        Dim i As Integer
        For i = 0 To pi.Length - 1
            listBox1.Items.Add(pi(i).Name)
        Next i
        textBox1.Text = "The SystemInformation class has " + pi.Length.ToString() + " properties." + ControlChars.CrLf
        
        ' Configure the list item selected handler for the list box to invoke a 
        ' method that displays the value of each property.
        AddHandler listBox1.SelectedIndexChanged, AddressOf listBox1_SelectedIndexChanged
        
        Me.ResumeLayout(False)
    End Sub    
    
    Private Sub listBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
        ' Return if no list item is selected.
        If listBox1.SelectedIndex = - 1 Then
            Return
        End If         
        ' Get the property name from the list item.
        Dim propname As String = listBox1.Text
        
        If propname = "PowerStatus" Then
            ' Cycle and display the values of each property of the PowerStatus property.
            textBox1.Text += ControlChars.CrLf + "The value of the PowerStatus property is:"
            Dim t As Type = GetType(System.Windows.Forms.PowerStatus)
            Dim pi As PropertyInfo() = t.GetProperties()
            Dim i As Integer
            For i = 0 To pi.Length - 1
                Dim propval As Object = pi(i).GetValue(SystemInformation.PowerStatus, Nothing)
                textBox1.Text += ControlChars.CrLf + "    PowerStatus." + pi(i).Name + " is: " + propval.ToString()
            Next i
        Else
            ' Display the value of the selected property of the SystemInformation type.
            Dim t As Type = GetType(System.Windows.Forms.SystemInformation)
            Dim pi As PropertyInfo() = t.GetProperties()
            Dim prop As PropertyInfo = Nothing
            Dim i As Integer
            For i = 0 To pi.Length - 1
                If pi(i).Name = propname Then
                    prop = pi(i)
                    Exit For
                End If
            Next i
            Dim propval As Object = prop.GetValue(Nothing, Nothing)
            textBox1.Text += ControlChars.CrLf + "The value of the " + propname + " property is: " + propval.ToString()
        End If
    End Sub    
    
    Private Sub InitForm()
        ' Initialize the form settings
        Me.listBox1 = New System.Windows.Forms.ListBox()
        Me.textBox1 = New System.Windows.Forms.TextBox()
        Me.listBox1.Anchor = CType(System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right, System.Windows.Forms.AnchorStyles)
        Me.listBox1.Location = New System.Drawing.Point(8, 16)
        Me.listBox1.Size = New System.Drawing.Size(172, 496)
        Me.listBox1.TabIndex = 0
        Me.textBox1.Anchor = CType(System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right, System.Windows.Forms.AnchorStyles)
        Me.textBox1.Location = New System.Drawing.Point(188, 16)
        Me.textBox1.Multiline = True
        Me.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.textBox1.Size = New System.Drawing.Size(420, 496)
        Me.textBox1.TabIndex = 1
        Me.ClientSize = New System.Drawing.Size(616, 525)
        Me.Controls.Add(Me.textBox1)
        Me.Controls.Add(Me.listBox1)
        Me.Text = "Select a SystemInformation property to get the value of"
    End Sub
        
    <STAThread()>  _
    Shared Sub Main()
        Application.Run(New SystemInfoBrowserForm())
    End Sub

End Class

備註

類別 SystemInformation 提供 static 屬性,可用來取得目前系統內容的相關資訊。 類別可讓您存取訊號,例如Windows顯示專案大小、作業系統設定、網路可用性,以及安裝在系統上的硬體功能。 無法執行個體化這個類別。

如需全系統參數的詳細資訊,請參閱 SystemParametersInfo

屬性

ActiveWindowTrackingDelay

取得使用中視窗追蹤延遲。

ArrangeDirection

取得值,表示作業系統排列最小化視窗的方向。

ArrangeStartingPosition

取得 ArrangeStartingPosition 值,表示作業系統排列最小化視窗的起始位置。

BootMode

取得 BootMode 值,表示啟動系統的開機模式。

Border3DSize

取得 3D 樣式視窗或系統控制項框線的粗細 (以像素為單位)。

BorderMultiplierFactor

取得框線乘數因數,用於決定視窗之縮放邊框的粗細。

BorderSize

取得平面樣式視窗或系統控制項框線的粗細 (以像素為單位)。

CaptionButtonSize

取得視窗標題列中按鈕的標準大小,以像素為單位。

CaptionHeight

取得視窗標準標題列區域的高度 (以像素為單位)。

CaretBlinkTime

取得插入號閃爍時間。

CaretWidth

取得編輯控制項中插入號的寬度,以像素為單位。

ComputerName

取得本機電腦的 NetBIOS 電腦名稱。

CursorSize

取得游標大小的最大值 (以像素為單位)。

DbcsEnabled

取得值,指出作業系統是否能夠處理雙位元組字元集 (DBCS) 字元。

DebugOS

取得值,指出是否已安裝 USER.EXE 的偵錯版本。

DoubleClickSize

取得區域的大小 (以像素為單位),使用者在該區域中必須按兩次滑鼠,作業系統才能將這個按兩次滑鼠動作視為按兩下滑鼠。

DoubleClickTime

取得第一次按滑鼠動作和第二次按滑鼠動作間所允許的最大毫秒數,如此 OS 才能將滑鼠動作視為按兩下滑鼠。

DragFullWindows

取得值,指出使用者是否已啟用完整的視窗拖曳。

DragSize

取得矩形的寬度和高度,該矩形以按下滑鼠按鈕的點為中心,在該矩形內不會開始拖曳作業。

FixedFrameBorderSize

取得視窗框架框線的粗細 (以像素為單位),該視窗具有標題且視窗大小不可調整。

FontSmoothingContrast

取得在 ClearType 平滑化中所使用的字型平滑化對比值。

FontSmoothingType

取得目前的字型平滑化類型。

FrameBorderSize

取得邊框的粗細 (以像素為單位),該邊框繪製於正在拖曳以調整大小之視窗的周邊。

HighContrast

取得值,表示使用者是否已啟用高對比模式協助工具功能。

HorizontalFocusThickness

取得系統焦點矩形左右邊緣的厚度,以像素為單位。

HorizontalResizeBorderThickness

取得要被調整大小的視窗周圍之縮放邊框左右邊緣的厚度,以像素為單位。

HorizontalScrollBarArrowWidth

取得水平捲軸的箭號點陣圖寬度 (以像素為單位)。

HorizontalScrollBarHeight

取得水平捲軸的預設高度 (以像素為單位)。

HorizontalScrollBarThumbWidth

取得水平捲軸的捲動方塊寬度 (以像素為單位)。

IconHorizontalSpacing

取得大圖示檢視中一個圖示排列儲存格的寬度,以像素為單位。

IconSize

取得 Windows 預設程式圖示大小 (以像素為單位)。

IconSpacingSize

取得方格大小 (以像素為單位),該方格用於在大型圖示檢視中排列圖示。

IconVerticalSpacing

取得大圖示檢視中一個圖示排列儲存格的高度,以像素為單位。

IsActiveWindowTrackingEnabled

取得一個值,指出使用中視窗追蹤是否已啟用。

IsComboBoxAnimationEnabled

取得一個值,指出下拉式方塊的滑開效果是否已啟用。

IsDropShadowEnabled

取得值,指出是否已啟用下拉式陰影效果。

IsFlatMenuEnabled

取得值,表示原生使用者功能表是否具有平面功能表外觀。

IsFontSmoothingEnabled

取得值,表示是否已啟用字型平滑化。

IsHotTrackingEnabled

取得值,指出使用者介面項目 (例如功能表列上的功能表名稱) 的熱追蹤是否已啟用。

IsIconTitleWrappingEnabled

取得值,指出是否已啟用圖示標題換行。

IsKeyboardPreferred

取得一個值,指出使用者是否主要使用鍵盤而非滑鼠,而且偏好在應用程式中顯示一般情況下會被隱藏的鍵盤介面。

IsListBoxSmoothScrollingEnabled

取得值,指出清單方塊的平滑捲動效果是否已啟用。

IsMenuAnimationEnabled

取得一個值,指出功能表淡出或滑動動畫功能是否已啟用。

IsMenuFadeEnabled

取得值,指出功能表淡出動畫是否已啟用。

IsMinimizeRestoreAnimationEnabled

取得一個值,指出視窗最小化和還原動畫是否已啟用。

IsSelectionFadeEnabled

取得值,指出選取區域淡出效果是否已啟用。

IsSnapToDefaultEnabled

取得一個值,指出貼齊預設按鈕功能是否已啟用。

IsTitleBarGradientEnabled

取得值,指出視窗標題列的漸層效果是否已啟用。

IsToolTipAnimationEnabled

取得值,指出是否已啟用 ToolTip 動畫。

KanjiWindowHeight

取得 Windows 雙位元組字元集 (DBCS) 版螢幕下方的漢字視窗的高度 (以像素為單位)。

KeyboardDelay

取得鍵盤的重複輸入延遲設定。

KeyboardSpeed

取得鍵盤的重複速度設定。

MaxWindowTrackSize

取得具有標題和縮放邊框 (Sizing Border) 視窗的預設最大值。

MenuAccessKeysUnderlined

取得值,指出功能表便捷鍵是否一律加上底線。

MenuBarButtonSize

取得功能表列按鈕的預設寬度和功能表列的預設高度,以像素為單位。

MenuButtonSize

取得功能表按列鈕的預設大小 (以像素為單位)。

MenuCheckSize

取得功能表核取記號區域的預設大小 (以像素為單位)。

MenuFont

取得字型,用於在功能表上顯示文字。

MenuHeight

取得功能表中一行的高度 (以像素為單位)。

MenuShowDelay

取得時間 (以毫秒為單位),這是當滑鼠游標位於子功能表項目之上時,系統在顯示重疊的捷徑功能表前所等待的時間。

MidEastEnabled

取得值,表示作業系統是否已啟用希伯來文和阿拉伯文語言。

MinimizedWindowSize

取得一般最小化視窗的大小,單位為像素。

MinimizedWindowSpacingSize

取得排列時配置給每個最小化視窗的區域大小 (以像素為單位)。

MinimumWindowSize

取得視窗的最小寬度和高度 (以像素為單位)。

MinWindowTrackSize

取得在拖曳調整大小期間視窗可能佔領的預設大小最小值 (以像素為單位)。

MonitorCount

取得桌面上的顯示監視器數。

MonitorsSameDisplayFormat

取得值,表示是否所有顯示監視器都使用相同的像素色彩格式。

MouseButtons

取得滑鼠上的按鈕數目。

MouseButtonsSwapped

取得值,指出是否已調換滑鼠左右按鈕的功能。

MouseHoverSize

取得矩型的維度 (以像素為單位),滑鼠指標必須在此範圍內停留一段滑鼠暫留時間,才能產生滑鼠暫留訊息。

MouseHoverTime

取得時間 (以毫秒為單位),滑鼠指標在該段時間內必須停留在停留矩形內,才能產生滑鼠停留訊息。

MousePresent

取得值,表示是否已安裝指向裝置。

MouseSpeed

取得目前的滑鼠速度。

MouseWheelPresent

取得值,指出是否已安裝具有滑鼠滾輪的滑鼠。

MouseWheelScrollDelta

取得單一滑鼠滾輪旋轉增量的差異值數量。

MouseWheelScrollLines

取得轉動滑鼠滾輪時要捲動的行數。

NativeMouseWheelSupport

取得值,指出是否已安裝具有滑鼠滾輪的滑鼠。

Network

取得值,表示是否存在網路連接。

PenWindows

取得值,表示是否已安裝 Microsoft Windows for Pen Computing 擴充功能。

PopupMenuAlignment

取得快顯功能表要與對應的功能表列項目對齊的方向。

PowerStatus

取得目前的系統電源狀態。

PrimaryMonitorMaximizedWindowSize

取得主顯示器上最大化視窗的預設大小 (以像素為單位)。

PrimaryMonitorSize

取得主顯示器上目前的視訊模式大小 (以像素為單位)。

RightAlignedMenus

取得值,表示下拉式功能表是否與對應的工具列項目一同靠右對齊。

ScreenOrientation

取得螢幕的方向。

Secure

取得值,表示這個作業系統上是否存在「安全性管理員」。

ShowSounds

取得值,表示在應用程式提供可聽式資訊的情況下,使用者是否慣用應用程式提供視覺化資訊。

SizingBorderWidth

取得繪製在要調整大小的視窗周圍之縮放邊框的寬度,以像素為單位。

SmallCaptionButtonSize

取得小標題按鈕的寬度和小標題的高度,以像素為單位。

SmallIconSize

取得小圖示的大小 (以像素為單位)。

TerminalServerSession

取得值,表示呼叫處理是否與「終端機服務」用戶端工作階段相關聯。

ToolWindowCaptionButtonSize

取得小標題按鈕的大小,單位為像素。

ToolWindowCaptionHeight

取得工具視窗標題的高度 (以像素為單位)。

UIEffectsEnabled

取得值,表示是否已啟用使用者介面 (UI)。

UserDomainName

取得使用者所屬之網域的名稱。

UserInteractive

取得數值,指示目前的處理程序是否正執行於使用者互動模式中。

UserName

取得與目前執行緒相關聯的使用者名稱。

VerticalFocusThickness

取得系統焦點矩形上下邊緣的厚度,以像素為單位。

VerticalResizeBorderThickness

取得正在調整大小之視窗週邊縮放邊框的上下邊緣粗細 (以像素為單位)。

VerticalScrollBarArrowHeight

取得垂直捲軸的箭號點陣圖的高度,單位為像素。

VerticalScrollBarThumbHeight

取得垂直捲軸的捲動方塊高度,單位為像素。

VerticalScrollBarWidth

取得垂直捲軸的預設寬度 (以像素為單位)。

VirtualScreen

取得虛擬螢幕的界限。

WorkingArea

取得螢幕的工作區域大小 (以像素為單位)。

方法

GetBorderSizeForDpi(Int32)

針對指定的 DPI 值,取得平面樣式視窗或系統控制項框線的粗細 (以像素為單位)。

GetHorizontalScrollBarArrowWidthForDpi(Int32)

取得水平捲軸箭號點陣圖的寬度 (以像素為單位)。

GetHorizontalScrollBarHeightForDpi(Int32)

針對指定的 DPI 值,取得水平捲軸的預設高度 (以像素為單位)。

GetMenuFontForDpi(Int32)

取得用來顯示功能表上文字的字型,以用於變更指定顯示裝置的 DPI。

GetVerticalScrollBarWidthForDpi(Int32)

針對指定的 DPI 值,取得垂直捲軸的預設高度 (以像素為單位)。

VerticalScrollBarArrowHeightForDpi(Int32)

取得垂直捲軸箭號點陣圖的高度 (像素)。

適用於

另請參閱