共用方式為


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 性質。 執行此範例時,將以下程式碼貼入包含一個名為 Label label1 及兩個 ListBox 控制項 listbox1 和 listbox2 的表單。 在此範例中,確保表單與控制 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

備註

當控制項捕獲滑鼠時,無論游標是否在其邊界內,都會接收滑鼠輸入。 滑鼠通常只會在拖曳操作時被捕獲。

只有前景視窗能捕捉滑鼠。 當背景視窗嘗試執行時,視窗只會收到當滑鼠游標位於視窗可見區域時發生的滑鼠事件訊息。 此外,即使前景視窗捕捉了滑鼠,使用者仍可點擊其他視窗,將其帶到前景。

當滑鼠被捕捉時,快捷鍵應該無法使用。

適用於

另請參閱