Control.Enter 이벤트
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
컨트롤을 입력할 때 발생합니다.
public:
event EventHandler ^ Enter;
public event EventHandler Enter;
public event EventHandler? Enter;
member this.Enter : EventHandler
Public Custom Event Enter As EventHandler
이벤트 유형
예제
다음 코드 예제에서는 이벤트를 사용하여 Enter 특정 조건의 전경색과 배경색을 TextBox 변경합니다.
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 하여 포커스를 변경하는 경우 포커스 이벤트는 다음 순서대로 발생합니다.
마우스를 사용하거나 메서드를 호출하여 포커스를 Focus 변경하는 경우 포커스 이벤트는 다음 순서대로 발생합니다.
속성이 CausesValidation 설정된 falseValidating 경우 이벤트 및 Validated 이벤트가 표시되지 않습니다.
메모
Enter 및 Leave 이벤트는 클래스에 의해 표시되지 않습니다Form. 클래스의 Form 동등한 이벤트는 및 Deactivate 이벤트입니다Activated. Enter 및 Leave 이벤트는 계층 구조이며 적절한 컨트롤에 도달할 때까지 부모 체인을 위아래로 계단식으로 연결합니다. 예를 들어 두 개의 컨트롤이 Form 있고 각 GroupBox 컨트롤에 하나의 TextBox 컨트롤이 있다고 가정 GroupBox 합니다. caret를 한 TextBox 쪽에서 다른 Leave 으로 이동하면 이벤트 및 GroupBox에 대해 TextBox 이벤트가 발생하며 다른 GroupBox 이벤트 및 EnterTextBox에 대해 이벤트가 발생합니다.
주의
, GotFocus, Leave, ValidatingLostFocus또는 Validated 이벤트 처리기 내에서 포커스를 Enter설정하지 마세요. 이렇게 하면 애플리케이션 또는 운영 체제의 응답이 중지될 수 있습니다. 자세한 내용은 WM_KILLFOCUS "키보드 입력 참조" 섹션의 항목과 메시지 및 메시지 큐 정보 항목의 "메시지 교착 상태" 섹션을 참조하세요.
이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생시키기를 참조하십시오.