Visual Basic 中学校 > Visual Basic サンプル集 > Visual Basic サンプル集目次 >
マウスの位置をセットする
1.マウスを画面の左上に移動する
Windows.Forms.Cursor.Position = New Point(0, 0)
2.マウスを画面の中央に移動する
Dim Pos As Point '中央の位置を算出
Pos.X = Screen.PrimaryScreen.Bounds.Right \ 2
Pos.Y = Screen.PrimaryScreen.Bounds.Bottom \ 2'マウスの位置をセット
Windows.Forms.Cursor.Position = Pos
3.マウスをボタンの上に移動する
以下の例ではマウスをButton1の上に移動する。
Dim Pos As Point 'ボタンの中央の位置をクライアント座標で算出
Pos.X = Button1.Width \ 2
Pos.Y = Button1.Height \ 2'マウスの位置をスクリーン座標でセット
Windows.Forms.Cursor.Position = Button1.PointToScreen(Pos)