Control.MousePosition Control.MousePosition Control.MousePosition Control.MousePosition Property

Definición

Obtiene la posición del cursor del mouse en coordenadas de pantalla.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

Valor de propiedad

Point que contiene las coordenadas del cursor del mouse con relación a la esquina superior izquierda de la pantalla.A Point that contains the coordinates of the mouse cursor relative to the upper-left corner of the screen.

Ejemplos

En el ejemplo de código siguiente TreeNode se coloca una etiqueta en un estado editable cuando el usuario presiona ALT + E mientras el cursor del mouse se encuentra sobre el nodo de árbol.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. Una vez que el usuario haya terminado de editar la etiqueta, las etiquetas no se podrán volver a editar hasta que se vuelva a presionar la combinación de teclas 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. Este ejemplo requiere que tenga un TreeView en un. FormThis example requires that you have a TreeView on a Form. La vista de árbol también debe tener al menos TreeNode un en Nodes su colección.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 mose 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 mose 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 mose 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

Comentarios

La MousePosition propiedad devuelve un Point que representa la posición del cursor del mouse en el momento en que se hizo referencia a la propiedad.The MousePosition property returns a Point that represents the mouse cursor position at the time the property was referenced. Las coordenadas indican la posición en la pantalla, no en relación con el control, y se devuelven independientemente de si el cursor se coloca sobre el control.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. Las coordenadas de la esquina superior izquierda de la pantalla son 0, 0.The coordinates of the upper-left corner of the screen are 0,0.

La MousePosition propiedad es idéntica a la Cursor.Position propiedad.The MousePosition property is identical to the Cursor.Position property.

Se aplica a

Consulte también: