UIElement.IsMouseCaptured 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得值,指出是否將滑鼠擷取至這個項目。 這是相依性屬性。
public:
property bool IsMouseCaptured { bool get(); };
C#
public bool IsMouseCaptured { get; }
member this.IsMouseCaptured : bool
Public ReadOnly Property IsMouseCaptured As Boolean
如果項目具有滑鼠擷取,則為 true
;否則為 false
。 預設為 false
。
下列範例會根據是否已針對 專案擷取滑鼠來開啟或關閉滑鼠擷取狀態。
如果滑鼠擷取位於其他地方,滑鼠擷取就會設定為該專案。 如果專案具有滑鼠擷取,則會使用 Null 輸入呼叫 Mouse.Capture 來清除它。
C#
private void CaptureMouseCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("Mouse Command");
IInputElement target = Mouse.DirectlyOver;
target = target as Control;
if (target != null)
{
if (!target.IsMouseCaptured)
{
Mouse.Capture(target);
}
else
{
Mouse.Capture(null);
}
}
}
Private Sub CaptureMouseCommandExecuted(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
MessageBox.Show("Mouse Command")
Dim target As IInputElement = Mouse.DirectlyOver
target = TryCast(target, Control)
If target IsNot Nothing Then
If Not target.IsMouseCaptured Then
Mouse.Capture(target)
Else
Mouse.Capture(Nothing)
End If
End If
End Sub
滑鼠擷取狀態與進程內拖放作業有關。
識別碼欄位 | IsMouseCapturedProperty |
設定為 的中繼資料屬性 true |
無 |
產品 | 版本 |
---|---|
.NET Framework | 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 |