2 out of 2 rated this helpful - Rate this topic

Screen Class

Represents a display device or multiple display devices on a single system.

System.Object
  System.Windows.Forms.Screen

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

The Screen type exposes the following members.

  Name Description
Public property Static member AllScreens Gets an array of all displays on the system.
Public property BitsPerPixel Gets the number of bits of memory, associated with one pixel of data.
Public property Bounds Gets the bounds of the display.
Public property DeviceName Gets the device name associated with a display.
Public property Primary Gets a value indicating whether a particular display is the primary device.
Public property Static member PrimaryScreen Gets the primary display.
Public property WorkingArea Gets the working area of the display. The working area is the desktop area of the display, excluding taskbars, docked windows, and docked tool bars.
Top
  Name Description
Public method Equals Gets or sets a value indicating whether the specified object is equal to this Screen. (Overrides Object.Equals(Object).)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Static member FromControl Retrieves a Screen for the display that contains the largest portion of the specified control.
Public method Static member FromHandle Retrieves a Screen for the display that contains the largest portion of the object referred to by the specified handle.
Public method Static member FromPoint Retrieves a Screen for the display that contains the specified point.
Public method Static member FromRectangle Retrieves a Screen for the display that contains the largest portion of the rectangle.
Public method Static member GetBounds(Control) Retrieves the bounds of the display that contains the largest portion of the specified control.
Public method Static member GetBounds(Point) Retrieves the bounds of the display that contains the specified point.
Public method Static member GetBounds(Rectangle) Retrieves the bounds of the display that contains the largest portion of the specified rectangle.
Public method GetHashCode Computes and retrieves a hash code for an object. (Overrides Object.GetHashCode().)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Static member GetWorkingArea(Control) Retrieves the working area for the display that contains the largest region of the specified control. The working area is the desktop area of the display, excluding taskbars, docked windows, and docked tool bars.
Public method Static member GetWorkingArea(Point) Retrieves the working area closest to the specified point. The working area is the desktop area of the display, excluding taskbars, docked windows, and docked tool bars.
Public method Static member GetWorkingArea(Rectangle) Retrieves the working area for the display that contains the largest portion of the specified rectangle. The working area is the desktop area of the display, excluding taskbars, docked windows, and docked tool bars.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Retrieves a string representing this object. (Overrides Object.ToString().)
Top

The constructor for this object is not public, so you cannot explicitly create a Screen object. The object is created when you call its public methods.

The following code example shows how to use various methods and properties of the Screen class. The example calls the AllScreens property to retrieve an array of all the screens connected to the system. For each returned Screen, the example adds the device name, bounds, type, working area, and primary screen to a ListBox. To use the example, add a ListBox and a Button to a form, and then add a Click event handler for the button.


private void button1_Click(object sender, System.EventArgs e)
{
    // For each screen, add the screen properties to a list box.
    foreach (var screen in System.Windows.Forms.Screen.AllScreens)
    {
        listBox1.Items.Add("Device Name: " + screen.DeviceName);
        listBox1.Items.Add("Bounds: " + 
            screen.Bounds.ToString());
        listBox1.Items.Add("Type: " + 
            screen.GetType().ToString());
        listBox1.Items.Add("Working Area: " + 
            screen.WorkingArea.ToString());
        listBox1.Items.Add("Primary Screen: " + 
            screen.Primary.ToString());
    }

}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Add Physical Dimension Properties to the Screen Class
http://connect.microsoft.com/VisualStudio/feedback/details/526951/screen-object-physicalwidthincentimeters-physicalheightincentimeters-displaymode
Add Physical Dimension Properties to the Screen Class
http://connect.microsoft.com/VisualStudio/feedback/details/526951/screen-object-physicalwidthincentimeters-physicalheightincentimeters-displaymode
Not an error
That's not an error, Phil.  When you use "var", the compiler deduces the type from the right side of the expression.

That does require C# 3.0 or later, however.
Minor error in c# example
  foreach (var screen in System.Windows.Forms.Screen.AllScreens)

should be:

foreach (Screen screen in System.Windows.Forms.Screen.AllScreens)