Control.Capture Propiedad

Definición

Obtiene o establece un valor que indica si el control ha capturado el mouse.Gets or sets a value indicating whether the control has captured the mouse.

public:
 property bool Capture { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public bool Capture { get; set; }
member this.Capture : bool with get, set
Public Property Capture As Boolean

Valor de propiedad

true si el control ha capturado el mouse; en caso contrario, false.true if the control has captured the mouse; otherwise, false.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra la propiedad Capture.The following code example demonstrates the Capture property. Para ejecutar este ejemplo, pegue el código siguiente en un formulario que contenga un Label denominado Label1 y dos controles ListBox denominados ListBox1 y listbox2.To run this example paste the following code in a form containing a Label named label1 and two ListBox controls named listbox1 and listbox2. Asegúrese de que el método y el evento MouseDown del formulario está asociado con el método en este ejemplo.Ensure the form and controls' MouseDown event is associated with the method in this example.

// This method handles the mouse down event for all the controls on the form.  
// When a control has captured the mouse
// the control's name will be output on label1.
void Control_MouseDown( System::Object^ sender,
   System::Windows::Forms::MouseEventArgs^ /*e*/ )
{
   Control^ control = (Control^)(sender);
   if ( control->Capture )
   {
      label1->Text = control->Name + " has captured the mouse";
   }
}
// This method handles the mouse down event for all the controls on the form.  
// When a control has captured the mouse
// the control's name will be output on label1.
private void Control_MouseDown(System.Object sender, 
    System.Windows.Forms.MouseEventArgs e)
{
    Control control = (Control) sender;
    if (control.Capture)
    {
        label1.Text = control.Name+" has captured the mouse";
    }
}
'This method handles the mouse down event for all the controls on the form.  When a control has
'captured the mouse, the control's name will be output on label1.
Private Sub Control_MouseDown(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown, _
    label1.MouseDown, listbox1.MouseDown, listbox2.MouseDown
    Dim control As Control = CType(sender, Control)
    If (control.Capture) Then
        label1.Text = control.Name & " has captured the mouse"
    End If
End Sub

Comentarios

Cuando un control ha capturado el mouse, recibe la entrada del mouse tanto si el cursor está dentro de sus bordes como si no lo está.When a control has captured the mouse, it receives mouse input whether or not the cursor is within its borders. Normalmente, el mouse solo se captura durante las operaciones de arrastre.The mouse is typically only captured during drag operations.

Solo la ventana de primer plano puede capturar el mouse.Only the foreground window can capture the mouse. Cuando una ventana en segundo plano intenta hacerlo, la ventana recibe mensajes solo de los eventos del mouse que se producen cuando el cursor del mouse está dentro de la parte visible de la ventana.When a background window attempts to do so, the window receives messages only for mouse events that occur when the mouse cursor is within the visible portion of the window. Además, incluso si la ventana de primer plano ha capturado el mouse, el usuario todavía puede hacer clic en otra ventana y colocarla en primer plano.Also, even if the foreground window has captured the mouse, the user can still click another window, bringing it to the foreground.

Cuando se captura el mouse, las teclas de método abreviado no deberían funcionar.When the mouse is captured, shortcut keys should not work.

Seguridad

UIPermission
para que todas las ventanas establezcan este valor de propiedad.for all windows to set this property value. Enumeración asociada: AllWindowsAssociated enumeration: AllWindows

Se aplica a

Consulte también: