Control.MouseCaptureChanged Событие
Определение
Происходит при потере захвата мыши элементом управления.Occurs when the control loses mouse capture.
public:
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)
{
System.Diagnostics.Debug.WriteLine("button1_MouseDown");
}
private void button1_MouseUp(object sender, MouseEventArgs e)
{
System.Diagnostics.Debug.WriteLine("button1_MouseUp");
}
private void button1_MouseCaptureChanged(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("button1_MouseCaptureChanged");
}
Private Sub Button1_MouseDown(ByVal sender As System.Object, _
ByVal e As MouseEventArgs) Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
End Sub
Private Sub Button1_MouseUp(ByVal sender As System.Object, _
ByVal e As MouseEventArgs) Handles Button1.MouseUp
Debug.WriteLine("Button1_MouseUp")
End Sub
Private Sub Button1_MouseCaptureChanged(ByVal sender As System.Object, _
ByVal e As EventArgs) Handles Button1.MouseCaptureChanged
Debug.WriteLine("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.
button1_MouseDown
button1_MouseUp
button1_MouseCaptureChanged
Теперь щелкните и удерживайте левую кнопку мыши на элементе управления 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.
button1_MouseDown
button1_MouseCaptureChanged
Комментарии
В редких случаях может потребоваться обнаружить непредвиденные входные данные.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.