次の方法で共有


Screen.FromPoint メソッド

指定したポイントを保持するディスプレイを表す Screen を取得します。

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

パラメータ

  • point
    Screen の取得条件となる位置を指定する Point

戻り値

ポイントを保持するディスプレイを表す Screen 。ポイントを保持するディスプレイがない複数ディスプレイ環境では、指定したポイントに最も近いディスプレイが返されます。

使用例

[Visual Basic, C#, C++] FromPoint メソッドを使用する方法の例を次に示します。この例では、 MouseEventArgs によって渡された X 座標と Y 座標を参照する Point を作成し、 FromPoint メソッドを使用して、クリックされたポイントがプライマリ画面上にあるかどうかを確認します。

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Screen クラス | Screen メンバ | System.Windows.Forms 名前空間 | FromControl | FromHandle | FromRectangle