Screen.FromPoint(Point) 方法

定义

Screen检索包含指定点的显示。

public:
 static System::Windows::Forms::Screen ^ FromPoint(System::Drawing::Point point);
public static System.Windows.Forms.Screen FromPoint(System.Drawing.Point point);
static member FromPoint : System.Drawing.Point -> System.Windows.Forms.Screen
Public Shared Function FromPoint (point As Point) As Screen

参数

point
Point

一个 Point ,指定要检索 Screen其位置。

返回

包含点的显示器的 A Screen 。 在没有显示点的多个显示环境中,将返回最接近指定点的显示器。

示例

下面的代码示例演示如何使用 FromPoint 该方法。 此示例创建引用Point由 a X传递的YMouseEventArgs坐标,然后使用FromPoint该方法来确定单击的点是否位于主屏幕上。

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( "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.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 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

适用于

另请参阅