Control.Capture Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą, czy kontrolka przechwyciła mysz.

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

Wartość właściwości

true jeśli kontrolka przechwyciła mysz; w przeciwnym razie , false.

Atrybuty

Przykłady

Poniższy przykład kodu przedstawia Capture właściwość . Aby uruchomić ten przykład, wklej następujący kod w formularzu zawierającym Label nazwę label1 i dwie ListBox kontrolki o nazwie listbox1 i listbox2. Upewnij się, że zdarzenie formularza i kontrolek MouseDown jest skojarzone z metodą w tym przykładzie.

// 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

Uwagi

Gdy kontrolka przechwyciła mysz, otrzymuje dane wejściowe myszy, czy kursor znajduje się w jego granicach. Mysz jest zwykle przechwytywana tylko podczas operacji przeciągania.

Tylko okno pierwszego planu może przechwycić mysz. Gdy okno tła próbuje to zrobić, okno odbiera komunikaty tylko dla zdarzeń myszy, które występują, gdy kursor myszy znajduje się w widocznej części okna. Ponadto nawet jeśli okno pierwszego planu przechwyciło mysz, użytkownik nadal może kliknąć inne okno, przenosząc go na pierwszy plan.

Po przechwyceniu myszy klawisze skrótów nie powinny działać.

Dotyczy

Zobacz też