Control.Capture 屬性

定義

取得或設定值,指出控制項是否捕捉住滑鼠。

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

屬性值

如果控制項捕捉住滑鼠,則為 true,否則為 false

屬性

範例

下列程式碼範例示範 Capture 屬性。 若要執行此範例,請將下列程式碼貼到包含具名 label1 的表單中,以及名為 listbox1 和 listbox2 的兩 ListBoxLabel 控制項。 請確定表單和控制項 MouseDown 的事件與此範例中的 方法相關聯。

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

備註

當控制項擷取滑鼠時,無論游標是否在其框線內,它都會收到滑鼠輸入。 滑鼠通常只會在拖曳作業期間擷取。

只有前景視窗可以擷取滑鼠。 當背景視窗嘗試這樣做時,視窗只會接收當滑鼠游標位於視窗可見部分時所發生的滑鼠事件訊息。 此外,即使前景視窗已擷取滑鼠,使用者仍然可以按一下另一個視窗,將它帶入前景。

擷取滑鼠時,快速鍵不應該運作。

適用於

另請參閱