Control.MouseCaptureChanged Control.MouseCaptureChanged Control.MouseCaptureChanged Control.MouseCaptureChanged Event


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

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


下列程式碼範例示範MouseCaptureChanged事件Button控制項。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.