SystemInformation 类

定义

提供有关当前系统环境的信息。

public ref class SystemInformation
public class SystemInformation
type SystemInformation = class
Public Class SystemInformation
继承
SystemInformation

示例

下面的代码示例列出类SystemInformation的所有属性ListBox,并在选定列表项时显示属性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

获取三维(三维)样式窗口或系统控制边框的粗细(以像素为单位)。

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

获取具有标题和大小调整边框的窗口的默认最大尺寸(以像素为单位)。

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

获取一个值,该值指示是否安装了适用于触控笔计算扩展的 windows Microsoft。

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

获取屏幕工作区的大小(以像素为单位)。

方法

名称 说明
Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetBorderSizeForDpi(Int32)

获取给定 DPI 值的平面样式窗口或系统控制边框的粗细(以像素为单位)。

GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetHorizontalScrollBarArrowWidthForDpi(Int32)

获取水平滚动条箭头位图的宽度(以像素为单位)。

GetHorizontalScrollBarHeightForDpi(Int32)

获取给定 DPI 值的水平滚动条的默认高度(以像素为单位)。

GetMenuFontForDpi(Int32)

获取用于在菜单上显示文本的字体,以便在更改给定显示设备的 DPI 时使用。

GetType()

获取当前实例的 Type

(继承自 Object)
GetVerticalScrollBarWidthForDpi(Int32)

获取给定 DPI 值垂直滚动条的默认高度(以像素为单位)。

MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)
VerticalScrollBarArrowHeightForDpi(Int32)

获取垂直滚动条箭头位图的高度(以像素为单位)。

适用于

另请参阅