Control.Leave 이벤트

정의

입력 포커스가 컨트롤을 벗어나면 발생합니다.

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

이벤트 유형

예제

다음 코드 예제에서는 사용 된 Leave 이전 상태로 컨트롤을 다시 설정 하는 이벤트입니다.

private:
   void textBox1_Enter( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // If the TextBox contains text, change its foreground and background colors.
      if ( textBox1->Text != String::Empty )
      {
         textBox1->ForeColor = Color::Red;
         textBox1->BackColor = Color::Black;

         // Move the selection pointer to the end of the text of the control.
         textBox1->Select(textBox1->Text->Length,0);
      }
   }

   void textBox1_Leave( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Reset the colors and selection of the TextBox after focus is lost.
      textBox1->ForeColor = Color::Black;
      textBox1->BackColor = Color::White;
      textBox1->Select(0,0);
   }
private void textBox1_Enter(object sender, System.EventArgs e)
{
    // If the TextBox contains text, change its foreground and background colors.
    if (!string.IsNullOrEmpty(textBox1.Text))
    {
        textBox1.ForeColor = Color.Red;
        textBox1.BackColor = Color.Black;
        // Move the selection pointer to the end of the text of the control.
        textBox1.Select(textBox1.Text.Length, 0);
    }
}

private void textBox1_Leave(object sender, System.EventArgs e)
{
    // Reset the colors and selection of the TextBox after focus is lost.
    textBox1.ForeColor = Color.Black;
    textBox1.BackColor = Color.White;
    textBox1.Select(0,0);
}
    Private Sub textBox1_Enter(sender As Object, e As System.EventArgs) Handles textBox1.Enter
        ' If the TextBox contains text, change its foreground and background colors.
        If textBox1.Text <> [String].Empty Then
            textBox1.ForeColor = Color.Red
            textBox1.BackColor = Color.Black
            ' Move the selection pointer to the end of the text of the control.
            textBox1.Select(textBox1.Text.Length, 0)
        End If
    End Sub
   
   
    Private Sub textBox1_Leave(sender As Object, e As System.EventArgs) Handles textBox1.Leave
        ' Reset the colors and selection of the TextBox after focus is lost.
        textBox1.ForeColor = Color.Black
        textBox1.BackColor = Color.White
        textBox1.Select(0, 0)
    End Sub
End Class

설명

호출 하 여 키보드 (TAB, SHIFT + TAB 등)를 사용 하 여 포커스를 변경 하면 합니다 Select 또는 SelectNextControl 메서드를 설정 하거나를 ContainerControl.ActiveControl 속성을 현재 폼에 포커스 이벤트가 다음 순서 대로 발생:

  1. Enter

  2. GotFocus

  3. Leave

  4. Validating

  5. Validated

  6. LostFocus

마우스를 사용 하 여 또는 호출 하 여 포커스를 변경 하면를 Focus 메서드 포커스 이벤트가 다음 순서 대로 발생 합니다.

  1. Enter

  2. GotFocus

  3. LostFocus

  4. Leave

  5. Validating

  6. Validated

경우는 CausesValidation 속성이 falseValidatingValidated 이벤트는 표시 되지 않습니다.

참고

EnterLeave 이벤트는 클래스에 의해 Form 표시되지 않습니다. 클래스의 Form 동등한 이벤트는 및 Deactivate 이벤트입니다Activated. EnterLeave 이벤트는 계층적이며 적절한 컨트롤에 도달할 때까지 부모 체인을 위아래로 계단식으로 연결합니다. 예를 들어 에는 두 개의 GroupBox 컨트롤이 Form 있고 각 GroupBox 컨트롤에는 하나의 TextBox 컨트롤이 있다고 가정합니다. 캐리트가 한 TextBox 쪽에서 다른 Leave 으로 이동하면 및 GroupBox에 대한 TextBox 이벤트가 발생하고 다른 GroupBoxTextBoxEnter 에 대해 이벤트가 발생합니다.

주의

, , , GotFocus, ValidatingLeaveLostFocus또는 Validated 이벤트 처리기 내에서 포커스를 Enter설정하지 마세요. 이렇게 하면 애플리케이션 또는 운영 체제 응답 하지 발생할 수 있습니다. 자세한 내용은 WM_KILLFOCUS 항목을 참조하세요.

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.

적용 대상

추가 정보