Control.Capture 屬性

定義

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

C#
[System.ComponentModel.Browsable(false)]
public bool Capture { get; set; }

屬性值

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

屬性

範例

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

C#
// 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";
    }
}

備註

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

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

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

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱