Screen.FromPoint(Point) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
擷取包含指定點之顯示的 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
參數
傳回
包含點之顯示的 Screen。 在任何顯示皆不包含點的多重顯示環境中,會傳回離指定點最近的顯示。
範例
下列程式碼範例示範如何使用 FromPoint 方法。 這個範例會 Point 建立 參考 所 MouseEventArgs 傳遞的 X 和 Y 座標,然後使用 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