Control.Capture 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示控件是否已捕获鼠标。
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
注解
当控件捕获了鼠标时,无论光标是否在其边框内,它都会接收鼠标输入。 通常仅在拖动操作期间捕获鼠标。
只有前台窗口可以捕获鼠标。 当后台窗口尝试执行此操作时,窗口仅接收当鼠标光标位于窗口的可见部分时发生的鼠标事件的消息。 此外,即使前台窗口已捕获鼠标,用户仍可以单击另一个窗口,将其带到前台。
捕获鼠标时,快捷键不应工作。