Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Screen.FromPoint Method

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

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

public static Screen FromPoint (
	Point point
)
public static Screen FromPoint (
	Point point
)
public static function FromPoint (
	point : Point
) : Screen
Not applicable.

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.

The following code 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.

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");
}

private void Form1_MouseDown(Object sender, System.Windows.Forms.
    MouseEventArgs e)
{
    Point p = new Point(e.get_X(), e.get_Y());
    Screen s = Screen.FromPoint(p);

    if (s.get_Primary()) {
        MessageBox.Show("You clicked the primary screen");
    }
    else {
        MessageBox.Show("This isn't the primary screen");
    }

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.