Screen 类

表示单个系统上的一个或多个显示设备。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Class Screen
用法
Dim instance As Screen
public class Screen
public ref class Screen
public class Screen
public class Screen

备注

此对象的构造函数不是公共的,因此您无法显式创建 Screen 对象。该对象在您调用其公共方法时创建。

示例

下面的代码示例演示如何使用 Screen 类的各种方法和属性。该示例调用 AllScreens 属性来检索连接到系统的所有屏幕的数组。对于每个返回的 Screen,该示例将设备名称、边界、类型、工作区和主屏幕添加到 ListBox

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGetScreenInfo.Click

    Dim Index As Integer
    Dim UpperBound As Integer

    ' Gets an array of all the screens connected to the system.

    Dim Screens() As System.Windows.Forms.Screen = _
        System.Windows.Forms.Screen.AllScreens
    UpperBound = Screens.GetUpperBound(0)

    For Index = 0 To UpperBound

        ' For each screen, add the screen properties to a list box.

        ListBox1.Items.Add("Device Name: " + Screens(Index).DeviceName)
        ListBox1.Items.Add("Bounds: " + Screens(Index).Bounds.ToString())
        ListBox1.Items.Add("Type: " + Screens(Index).GetType().ToString())
        ListBox1.Items.Add("Working Area: " + Screens(Index).WorkingArea.ToString())
        ListBox1.Items.Add("Primary Screen: " + Screens(Index).Primary.ToString())

    Next



End Sub
private void button1_Click(object sender, System.EventArgs e)
{
    int index;
    int upperBound; 

    // Gets an array of all the screens connected to the system.

    Screen [] screens = Screen.AllScreens;
    upperBound = screens.GetUpperBound(0);

    for(index = 0; index <= upperBound; index++)
    {

        // For each screen, add the screen properties to a list box.

        listBox1.Items.Add("Device Name: " + screens[index].DeviceName);
        listBox1.Items.Add("Bounds: " + screens[index].Bounds.ToString());
        listBox1.Items.Add("Type: " + screens[index].GetType().ToString());
        listBox1.Items.Add("Working Area: " + screens[index].WorkingArea.ToString());
        listBox1.Items.Add("Primary Screen: " + screens[index].Primary.ToString());

    }

}
private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      int index;
      int upperBound;

      // Gets an array of all the screens connected to the system.
      array<Screen^>^screens = Screen::AllScreens;
      upperBound = screens->GetUpperBound( 0 );
      for ( index = 0; index <= upperBound; index++ )
      {
         // For each screen, add the screen properties to a list box.
         listBox1->Items->Add( String::Concat( "Device Name: ", screens[ index ]->DeviceName ) );
         listBox1->Items->Add( String::Concat( "Bounds: ", screens[ index ]->Bounds ) );
         listBox1->Items->Add( String::Concat( "Type: ", screens[ index ]->GetType() ) );
         listBox1->Items->Add( String::Concat( "Working Area: ", screens[ index ]->WorkingArea ) );
         listBox1->Items->Add( String::Concat( "Primary Screen: ", screens[ index ]->Primary ) );
      }
   }
private void button1_Click(Object sender, System.EventArgs e)
{
    int index;
    int upperBound;
    // Gets an array of all the screens connected to the system.
    Screen screens[] = Screen.get_AllScreens();
    upperBound = screens.GetUpperBound(0);

    for (index = 0; index <= upperBound; index++) {
        // For each screen, add the screen properties to a list box.
        listBox1.get_Items().Add("Device Name: " + screens[index].
            get_DeviceName());
        listBox1.get_Items().Add("Bounds: " + screens[index].get_Bounds()
            .ToString());
        listBox1.get_Items().Add("Type: " + screens[index].GetType().
            ToString());
        listBox1.get_Items().Add("Working Area: " + screens[index].
            get_WorkingArea().ToString());
        listBox1.get_Items().Add("Primary Screen: " + 
            ((System.Boolean)screens[index].get_Primary()).ToString());
    }
} //button1_Click

继承层次结构

System.Object
  System.Windows.Forms.Screen

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Screen 成员
System.Windows.Forms 命名空间