Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Screen Class
Screen Properties
 PrimaryScreen Property

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Screen..::.PrimaryScreen Property

Gets the primary display.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Declaration)
Public Shared ReadOnly Property PrimaryScreen As Screen
Visual Basic (Usage)
Dim value As Screen

value = Screen.PrimaryScreen
C#
public static Screen PrimaryScreen { get; }
Visual C++
public:
static property Screen^ PrimaryScreen {
    Screen^ get ();
}
JScript
public static function get PrimaryScreen () : Screen

Property Value

Type: System.Windows.Forms..::.Screen
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

Visual Basic
' This method will adjust the size of the form to utilize 
' the working area of the screen.

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

    ' Retrieve the working rectangle from the Screen class
    ' using the PrimaryScreen and the WorkingArea properties. 
    Dim workingRectangle As System.Drawing.Rectangle = _
        Screen.PrimaryScreen.WorkingArea

    ' Set the size of the form slightly less than size of 
    ' working rectangle.
    Me.Size = New System.Drawing.Size(workingRectangle.Width - 10, _
        workingRectangle.Height - 10)

    ' Set the location so the entire form is visible.
    Me.Location = New System.Drawing.Point(5, 5)

End Sub

C#
    // 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);
    }

Visual C++
   // 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 = System::Drawing::Size( workingRectangle.Width - 10, workingRectangle.Height - 10 );

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

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

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker