Control.MousePosition プロパティ

定義

マウス カーソルの位置を画面座標で取得します。Gets the position of the mouse cursor in screen coordinates.

public:
 static property System::Drawing::Point MousePosition { System::Drawing::Point get(); };
public static System.Drawing.Point MousePosition { get; }
member this.MousePosition : System.Drawing.Point
Public Shared ReadOnly Property MousePosition As Point

プロパティ値

Point

画面の左上隅に対する相対座標として、マウス カーソルの座標を格納している PointA Point that contains the coordinates of the mouse cursor relative to the upper-left corner of the screen.

次のコード例では、 TreeNode マウスカーソルがツリーノードの上にあるときに、ユーザーが ALT キーを押しながら E キーを押すと、ラベルが編集可能な状態になります。The following code example puts a TreeNode label into an editable state when the user presses ALT+E while the mouse cursor is over the tree node. ユーザーがラベルの編集を完了した後、ALT + E キーの組み合わせが再び押されるまで、ラベルを再度編集することはできません。After the user is done editing the label, the labels cannot be edited again until the ALT+E key combination is pressed again. この例では、にを設定する必要があり TreeView Form ます。This example requires that you have a TreeView on a Form. ツリービューのコレクションには、少なくとも1つのツリービューが必要 TreeNode Nodes です。The tree view should also have at least one TreeNode in its Nodes collection.

private:
   void treeView1_KeyDown( Object^ /*sender*/, KeyEventArgs^ e )
   {
      /* If the 'Alt' and 'E' keys are pressed,
         * allow the user to edit the TreeNode label. */
      if ( e->Alt && e->KeyCode == Keys::E )
      {
         treeView1->LabelEdit = true;
         
         // If there is a TreeNode under the mouse cursor, begin editing.
         TreeNode^ editNode = treeView1->GetNodeAt( treeView1->PointToClient( Control::MousePosition ) );
         if ( editNode != nullptr )
         {
            editNode->BeginEdit();
         }
      }
   }

   void treeView1_AfterLabelEdit( Object^ /*sender*/, NodeLabelEditEventArgs^ /*e*/ )
   {
      // Disable the ability to edit the TreeNode labels.
      treeView1->LabelEdit = false;
   }
private void treeView1_KeyDown(object sender, KeyEventArgs e)
{
   /* If the 'Alt' and 'E' keys are pressed,
      * allow the user to edit the TreeNode label. */
   if(e.Alt && e.KeyCode == Keys.E)
         
   {
      treeView1.LabelEdit = true;
      // If there is a TreeNode under the mouse cursor, begin editing. 
      TreeNode editNode = treeView1.GetNodeAt(
         treeView1.PointToClient(System.Windows.Forms.Control.MousePosition));
      if(editNode != null)
      { 
         editNode.BeginEdit();
      }
   }
}

private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
   // Disable the ability to edit the TreeNode labels.
   treeView1.LabelEdit = false;
}
Private Sub treeView1_KeyDown(sender As Object, _
  e As KeyEventArgs) Handles treeView1.KeyDown
   ' If the 'Alt' and 'E' keys are pressed,
   ' allow the user to edit the TreeNode label. 
   If e.Alt And e.KeyCode = Keys.E Then
      treeView1.LabelEdit = True
      ' If there is a TreeNode under the mouse cursor, begin editing. 
      Dim editNode As TreeNode = treeView1.GetNodeAt( _
        treeView1.PointToClient(System.Windows.Forms.Control.MousePosition))
      If (editNode IsNot Nothing) Then
         editNode.BeginEdit()
      End If
   End If
End Sub

Private Sub treeView1_AfterLabelEdit(sender As Object, _
  e As NodeLabelEditEventArgs) Handles treeView1.AfterLabelEdit
   ' Disable the ability to edit the TreeNode labels.
   treeView1.LabelEdit = False
End Sub

注釈

プロパティは、 MousePosition Point プロパティが参照されたときのマウスカーソル位置を表すを返します。The MousePosition property returns a Point that represents the mouse cursor position at the time the property was referenced. 座標は、コントロールに対して相対的ではなく、画面上の位置を示し、カーソルがコントロール上に配置されているかどうかに関係なく返されます。The coordinates indicate the position on the screen, not relative to the control, and are returned regardless of whether the cursor is positioned over the control. 画面の左上隅の座標は 0, 0 です。The coordinates of the upper-left corner of the screen are 0,0.

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

適用対象

こちらもご覧ください