Control.MouseCaptureChanged 事件


發生於控制項遺失滑鼠捕捉時。Occurs when the control loses mouse capture.

 event EventHandler ^ MouseCaptureChanged;
public event EventHandler MouseCaptureChanged;
member this.MouseCaptureChanged : EventHandler 
Public Custom Event MouseCaptureChanged As EventHandler 




下列程式碼範例示範 Button 控制項的 MouseCaptureChanged 事件。The following code example demonstrates the MouseCaptureChanged event for a Button control.

private void button1_MouseDown(object sender, MouseEventArgs e)

private void button1_MouseUp(object sender, MouseEventArgs e)

private void button1_MouseCaptureChanged(object sender, EventArgs e)
Private Sub Button1_MouseDown(ByVal sender As System.Object, _
ByVal e As MouseEventArgs) Handles Button1.MouseDown
End Sub

Private Sub Button1_MouseUp(ByVal sender As System.Object, _
ByVal e As MouseEventArgs) Handles Button1.MouseUp
End Sub

Private Sub Button1_MouseCaptureChanged(ByVal sender As System.Object, _
ByVal e As EventArgs) Handles Button1.MouseCaptureChanged
End Sub

若要測試此範例,請按 F5 在偵錯工具中執行。To test this example, run it in the debugger by pressing F5. 在 Visual Studio 中開啟 [輸出] 視窗,讓您可以查看事件引發的時間。Open the Output window in Visual Studio so that you can see when events are raised. 按一下 Button 並注意下列輸出。Click the Button and notice the following output.




現在,按一下並按住滑鼠左鍵,Button 控制項上。Now, click and hold the left mouse button on the Button control. 當仍然按一下滑鼠時,請按 ALT + TAB 切換至另一個程式。While still clicking the mouse, press ALT+TAB to switch to another program. 請注意,MouseCaptureChanged 事件會引發,讓您可以處理這種情況。Notice that the MouseCaptureChanged event is raised enabling you to potentially handle this scenario. 根據您的動作而定,可能不會引發 MouseUp 事件。Depending on your actions, the MouseUp event might not be raised. 您也可以使用 Windows 鍵或 CTRL + ESC 來嘗試這項測試。You can also try this test with the Windows key or CTRL+ESC.




在罕見的情況下,您可能需要偵測到非預期的輸入。In rare scenarios, you might need to detect unexpected input. 例如,請考慮下列案例。For example, consider the following scenarios.

  • 在滑鼠操作期間,使用者按下 Windows 鍵或 CTRL + ESC,即可開啟 [開始] 功能表。During a mouse operation, the user opens the Start menu by pressing the Windows key or CTRL+ESC.

  • 在滑鼠操作期間,使用者按下 ALT + TAB 切換至另一個程式。During a mouse operation, the user switches to another program by pressing ALT+TAB.

  • 在滑鼠作業期間,另一個程式會顯示視窗或訊息方塊,該方塊會將焦點放在目前的應用程式之外。During a mouse operation, another program displays a window or a message box that takes focus away from the current application.

滑鼠運算可以包含在表單或控制項上按一下和按住滑鼠,或執行滑鼠拖曳操作。Mouse operations can include clicking and holding the mouse on a form or a control, or performing a mouse drag operation. 如果您必須在表單或控制項失去這些和相關非預期案例的滑鼠捕捉時進行偵測,您可以使用 MouseCaptureChanged 事件。If you have to detect when a form or a control loses mouse capture for these and related unexpected scenarios, you can use the MouseCaptureChanged event.