Export (0) Print
Expand All

Screen.FromPoint Method

Retrieves a Screen for the display that contains the specified point.

[Visual Basic]
Public Shared Function FromPoint( _
   ByVal point As Point _
) As Screen
[C#]
public static Screen FromPoint(
 Point point
);
[C++]
public: static Screen* FromPoint(
 Point point
);
[JScript]
public static function FromPoint(
   point : Point
) : Screen;

Parameters

point
A Point that specifies the location for which to retrieve a Screen.

Return Value

A Screen for the display that contains the point. In multiple display environments where no display contains the point, the display closest to the specified point is returned.

Example

[Visual Basic, C#, C++] The following example shows how to use the FromPoint method. This example creates a Point referencing the X and Y coordinates passed by a MouseEventArgs, and then uses the FromPoint method to determine if the point clicked is on the primary screen.

[Visual Basic] 
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
    Dim p As New System.Drawing.Point(e.X, e.Y)
    Dim s As System.Windows.Forms.Screen = Screen.FromPoint(p)

    If s.Primary = True Then
        MessageBox.Show("You clicked the primary screen")
    Else
        MessageBox.Show("This isn't the primary screen")
    End If
End Sub

[C#] 
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
    Point p = new Point(e.X, e.Y);
    Screen s = Screen.FromPoint(p);
    
if (s.Primary)
{
    MessageBox.Show("You clicked the primary screen");
}
else
{
    MessageBox.Show("This isn't the primary screen");
}

[C++] 
private:
    void Form1_MouseDown(Object* /*sender*/, 
        System::Windows::Forms::MouseEventArgs* e) {

        Point p = Point(e->X, e->Y);
        Screen* s = Screen::FromPoint(p);

        if (s->Primary) {
            MessageBox::Show(S"You clicked the primary screen");
        } else {
            MessageBox::Show(S"This isn't the primary screen");
        }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Screen Class | Screen Members | System.Windows.Forms Namespace | FromControl | FromHandle | FromRectangle

Show:
© 2015 Microsoft