Control.Capture Control.Capture Control.Capture Control.Capture Property

定義

取得或設定值,指出控制項是否捕捉住滑鼠。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

屬性值

如果控制項捕捉住滑鼠,則為 true,否則為 falsetrue if the control has captured the mouse; otherwise, false.

範例

下列程式碼範例會示範Capture屬性。The following code example demonstrates the Capture property. 若要執行此範例, 請將下列程式碼貼入包含Label名為 label1 的ListBox表單中, 以及名為 listbox1 和 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. 請確定表單和控制項MouseDown的事件與此範例中的方法相關聯。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

備註

當控制項捕捉到滑鼠時, 不論游標是否在其框線內, 它都會收到滑鼠輸入。When a control has captured the mouse, it receives mouse input whether or not the cursor is within its borders. 滑鼠通常只會在拖曳作業期間捕捉。The mouse is typically only captured during drag operations.

只有前景視窗可以捕捉滑鼠。Only the foreground window can capture the mouse. 當背景視窗嘗試這麼做時, 視窗只會針對滑鼠游標位於視窗可見部分的滑鼠事件, 接收訊息。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. 此外, 即使前景視窗已捕捉過滑鼠, 使用者仍然可以按一下另一個視窗, 將其移至前景。Also, even if the foreground window has captured the mouse, the user can still click another window, bringing it to the foreground.

當捕捉到滑鼠時, 快速鍵不應作用。When the mouse is captured, shortcut keys should not work.

安全性

UIPermission
適用于所有視窗, 以設定此屬性值。for all windows to set this property value. 相關聯的列舉:AllWindowsAssociated enumeration: AllWindows

適用於

另請參閱