Cursor.Position プロパティ

定義

カーソルの位置を取得または設定します。Gets or sets the cursor's position.

public:
 static property System::Drawing::Point Position { System::Drawing::Point get(); void set(System::Drawing::Point value); };
public static System.Drawing.Point Position { get; set; }
member this.Position : System.Drawing.Point with get, set
Public Shared Property Position As Point

プロパティ値

カーソルの位置を画面座標で表す PointA Point that represents the cursor's position in screen coordinates.

次のコード例では、 CurrentカーソルのHandleからカーソルを作成し、その位置とクリッピング四角形を変更します。The following code example creates a cursor from the Current cursor's Handle, changes its position and clipping rectangle. その結果、カーソルが上に移動し、コードが実行された時点から左の50ピクセルに移動します。The result is the cursor will move up and to the left 50 pixels from where it is when the code is executed. さらに、カーソルのクリッピング四角形は、フォームの境界に変更されます (既定では、ユーザーの画面全体になります)。Additionally, the cursor's clipping rectangle is changed to the bounds of the form (by default it is the user's whole screen). この例ではForm 、がButtonクリックされたときにこのコードを呼び出すためにとが必要です。This example requires a Form and a Button to call this code when it is clicked.

void MoveCursor()
{
   // Set the Current cursor, move the cursor's Position,
   // and set its clipping rectangle to the form.

   this->Cursor = gcnew System::Windows::Forms::Cursor( ::Cursor::Current->Handle );
   ::Cursor::Position = Point(::Cursor::Position.X - 50,::Cursor::Position.Y - 50);
   ::Cursor::Clip = Rectangle(this->Location,this->Size);

}
private void MoveCursor()
{
   // Set the Current cursor, move the cursor's Position,
   // and set its clipping rectangle to the form. 

   this.Cursor = new Cursor(Cursor.Current.Handle);
   Cursor.Position = new Point(Cursor.Position.X - 50, Cursor.Position.Y - 50);
   Cursor.Clip = new Rectangle(this.Location, this.Size);
}
Private Sub MoveCursor()
   ' Set the Current cursor, move the cursor's Position,
   ' and set its clipping rectangle to the form. 

   Me.Cursor = New Cursor(Cursor.Current.Handle)
   Cursor.Position = New Point(Cursor.Position.X - 50, Cursor.Position.Y - 50)
   Cursor.Clip = New Rectangle(Me.Location, Me.Size)
End Sub

注釈

プロパティは、 Control.MousePositionプロパティと同じです。 PositionThe Position property is identical to the Control.MousePosition property.

適用対象

こちらもご覧ください