ヘッダー

VB.NET2002対応 VB.NET2003対応 VB2005対応

 

マウスの位置をセットする

1.マウスを画面の左上に移動する

VB.NET2002対応 VB.NET2003対応 VB2005対応


Windows.Forms.Cursor.Position =
New Point(0, 0)
 

 

2.マウスを画面の中央に移動する

VB.NET2002対応 VB.NET2003対応 VB2005対応

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の上に移動する。

VB.NET2002対応 VB.NET2003対応 VB2005対応

Dim Pos As Point

'ボタンの中央の位置をクライアント座標で算出
Pos.X = Button1.Width \ 2
Pos.Y = Button1.Height \ 2

'マウスの位置をスクリーン座標でセット
Windows.Forms.Cursor.Position = Button1.PointToScreen(Pos)