다음을 통해 공유


Control.Leave 이벤트

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

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public Event Leave As EventHandler
‘사용 방법
Dim instance As Control
Dim handler As EventHandler

AddHandler instance.Leave, handler
public event EventHandler Leave
public:
event EventHandler^ Leave {
    void add (EventHandler^ value);
    void remove (EventHandler^ value);
}
/** @event */
public void add_Leave (EventHandler value)

/** @event */
public void remove_Leave (EventHandler value)
JScript에서는 이벤트를 사용할 수 있지만 새로 선언할 수는 없습니다.

설명

키보드의 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 속성이 false로 설정되면 ValidatingValidated 이벤트는 발생하지 않습니다.

참고

Form 클래스는 EnterLeave 이벤트가 발생하지 않도록 합니다. Form 클래스의 해당하는 다른 이벤트로는 ActivatedDeactivate 이벤트가 있습니다. EnterLeave 이벤트는 계층적이며 적절한 컨트롤에 도달할 때까지 부모 체인을 위 아래로 캐스케이딩합니다. 예를 들어, 두 개의 GroupBox 컨트롤이 있는 Form에서 GroupBox 컨트롤마다 TextBox 컨트롤이 하나씩 있는 것으로 가정합니다. 캐럿이 한 TextBox 컨트롤에서 다른 컨트롤로 이동하면 TextBoxGroupBox에 대해서는 Leave 이벤트가 발생하고, 다른 GroupBoxTextBox에 대해서는 Enter 이벤트가 발생합니다.

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

예제

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

    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 'textBox1_Enter
   
   
    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 'textBox1_Leave
End Class 'Form1 
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);
    }
}

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:
   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 (!(textBox1.get_Text().Equals(""))) {
        textBox1.set_ForeColor(Color.get_Red());
        textBox1.set_BackColor(Color.get_Black());

        // Move the selection pointer to the end of the text of the 
        // control.
        textBox1.Select(textBox1.get_Text().get_Length(), 0);
    }
} //textBox1_Enter

private void textBox1_Leave(Object sender, System.EventArgs e)
{
    // Reset the colors and selection of the TextBox after focus is lost.
    textBox1.set_ForeColor(Color.get_Black());
    textBox1.set_BackColor(Color.get_White());
    textBox1.Select(0, 0);
} //textBox1_Leave

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

Control 클래스
Control 멤버
System.Windows.Forms 네임스페이스
OnLeave
Control.Enter 이벤트