Control.Capture 属性

获取或设置一个值,该值指示控件是否已捕获鼠标。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property Capture As Boolean
用法
Dim instance As Control
Dim value As Boolean

value = instance.Capture

instance.Capture = value
public bool Capture { get; set; }
public:
property bool Capture {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_Capture ()

/** @property */
public void set_Capture (boolean value)
public function get Capture () : boolean

public function set Capture (value : boolean)

属性值

如果控件已捕获鼠标,则为 true;否则为 false

备注

当控件已捕获鼠标时,它接收鼠标输入,不论光标是否在其边框内。通常只有在执行拖动操作时才捕获鼠标。

只有前景窗口能够捕获鼠标。当背景窗口试图捕获鼠标时,窗口只接收鼠标光标位于该窗口的可见部分时发生的鼠标事件的消息。此外,即使前景窗口已经捕获鼠标,用户仍可以单击另一个窗口,将它带到前景。

当捕获鼠标时,快捷键不起作用。

示例

下面的代码示例演示了 Capture 属性。要运行该示例,请将以下代码粘贴到一个窗体中(该窗体包含一个名为 label1 的 Label 和两个名为 listbox1 和 listbox2 Listbox 控件)。确保窗体和控件的 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.
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
// 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.
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(Object sender, 
    System.Windows.Forms.MouseEventArgs e)
{
    Control control = (Control)sender;
    if (control.get_Capture()) {
        label1.set_Text(control.get_Name() + " has captured the mouse");
    }
} //Control_MouseDown

.NET Framework 安全性

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Control 类
Control 成员
System.Windows.Forms 命名空间
Cursor