PrimaryScreen Property
Collapse the table of content
Expand the table of content

Screen.PrimaryScreen Property

Gets the primary display.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public static Screen PrimaryScreen { get; }
/** @property */
public static Screen get_PrimaryScreen ()

public static function get PrimaryScreen () : Screen

Not applicable.

Property Value

The primary display.

For a single display system, the primary display is the only display.

The following code example demonstrates the use of PrimaryScreen property and the GetWorkingArea method. This method requires a form containing a button named Button1

// This method will adjust the size of the form to utilize 
// the working area of the screen.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
    // Retrieve the working rectangle from the Screen class
    // using the PrimaryScreen and the WorkingArea properties.
    System.Drawing.Rectangle workingRectangle = 
        Screen.PrimaryScreen.WorkingArea;
    
    // Set the size of the form slightly less than size of 
    // working rectangle.
    this.Size = new System.Drawing.Size(
        workingRectangle.Width-10, workingRectangle.Height-10);

    // Set the location so the entire form is visible.
    this.Location = new System.Drawing.Point(5, 5);
}

// This method will adjust the size of the form to utilize 
// the working area of the screen.
private void button1_Click(Object sender, System.EventArgs e)
{
    // Retrieve the working rectangle from the Screen class
    // using the PrimaryScreen and the WorkingArea properties.
    System.Drawing.Rectangle workingRectangle =
        Screen.get_PrimaryScreen().get_WorkingArea();
    // Set the size of the form slightly less than size of 
    // working rectangle.
    this.set_Size(new System.Drawing.Size(workingRectangle.get_Width()
        - 10, workingRectangle.get_Height() - 10));
    // Set the location so the entire form is visible.
    this.set_Location(new System.Drawing.Point(5, 5));
} //Button1_Click

Windows 98, Windows Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2016 Microsoft