Control.Validated 이벤트
컨트롤의 유효성 검사가 완료되면 발생합니다.
네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)
구문
‘선언
Public Event Validated As EventHandler
‘사용 방법
Dim instance As Control
Dim handler As EventHandler
AddHandler instance.Validated, handler
public event EventHandler Validated
public:
event EventHandler^ Validated {
void add (EventHandler^ value);
void remove (EventHandler^ value);
}
/** @event */
public void add_Validated (EventHandler value)
/** @event */
public void remove_Validated (EventHandler value)
JScript에서는 이벤트를 사용할 수 있지만 새로 선언할 수는 없습니다.
설명
키보드의 Tab 키, Shift+Tab 등을 사용하거나 Select 또는 SelectNextControl 메서드를 호출하거나 ContainerControl.ActiveControl 속성을 현재 폼으로 설정하여 포커스를 변경하면 다음 순서로 포커스 이벤트가 발생합니다.
Validated
마우스를 사용하거나 Focus 메서드를 호출하여 포커스를 변경하면 다음 순서로 포커스 이벤트가 발생합니다.
Enter
GotFocus
LostFocus
Leave
Validating
Validated
CausesValidation 속성이 false로 설정되면 Validating 및 Validated 이벤트는 발생하지 않습니다.
CancelEventArgs의 Cancel 속성이 Validating 이벤트 대리자에서 true로 설정된 경우 일반적으로 Validating 이벤트 이후의 모든 이벤트는 발생하지 않습니다.
이벤트 처리에 대한 자세한 내용은 이벤트 사용을 참조하십시오.
예제
다음 코드 예제에서는 파생 클래스 TextBox를 사용하여 사용자가 입력한 전자 메일 주소의 유효성을 검사합니다. 전자 메일 주소의 형식이 "@"과 "."이 포함된 표준 형식이 아니면 유효성 검사가 실패하고, ErrorProvider 아이콘이 표시되며, 이벤트가 취소됩니다. 이 예제를 실행하려면 폼에 TextBox 및 ErrorProvider 컨트롤이 만들어져 있어야 합니다.
Private Function ValidEmailAddress(ByVal emailAddress As String, ByRef errorMessage As String) As Boolean
' Confirm there is text in the control.
If textBox1.Text.Length = 0 Then
errorMessage = "E-mail address is required."
Return False
End If
' Confirm that there is an "@" and a "." in the e-mail address, and in the correct order.
If emailAddress.IndexOf("@") > -1 Then
If (emailAddress.IndexOf(".", emailAddress.IndexOf("@")) > emailAddress.IndexOf("@")) Then
errorMessage = ""
Return True
End If
End If
errorMessage = "E-mail address must be valid e-mail address format." + ControlChars.Cr + _
"For example 'someone@example.com' "
Return False
End Function
Private Sub textBox1_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles textBox1.Validating
Dim errorMsg As String
If Not ValidEmailAddress(textBox1.Text, errorMsg) Then
' Cancel the event and select the text to be corrected by the user.
e.Cancel = True
textBox1.Select(0, textBox1.Text.Length)
' Set the ErrorProvider error with the text to display.
Me.errorProvider1.SetError(textBox1, errorMsg)
End If
End Sub
Private Sub textBox1_Validated(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles textBox1.Validated
' If all conditions have been met, clear the error provider of errors.
errorProvider1.SetError(textBox1, "")
End Sub
private void textBox1_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
string errorMsg;
if(!ValidEmailAddress(textBox1.Text, out errorMsg))
{
// Cancel the event and select the text to be corrected by the user.
e.Cancel = true;
textBox1.Select(0, textBox1.Text.Length);
// Set the ErrorProvider error with the text to display.
this.errorProvider1.SetError(textBox1, errorMsg);
}
}
private void textBox1_Validated(object sender, System.EventArgs e)
{
// If all conditions have been met, clear the ErrorProvider of errors.
errorProvider1.SetError(textBox1, "");
}
public bool ValidEmailAddress(string emailAddress, out string errorMessage)
{
// Confirm that the e-mail address string is not empty.
if(emailAddress.Length == 0)
{
errorMessage = "e-mail address is required.";
return false;
}
// Confirm that there is an "@" and a "." in the e-mail address, and in the correct order.
if(emailAddress.IndexOf("@") > -1)
{
if(emailAddress.IndexOf(".", emailAddress.IndexOf("@") ) > emailAddress.IndexOf("@") )
{
errorMessage = "";
return true;
}
}
errorMessage = "e-mail address must be valid e-mail address format.\n" +
"For example 'someone@example.com' ";
return false;
}
private:
void textBox1_Validating( Object^ sender, System::ComponentModel::CancelEventArgs^ e )
{
String^ errorMsg;
if ( !ValidEmailAddress( textBox1->Text, &errorMsg ) )
{
// Cancel the event and select the text to be corrected by the user.
e->Cancel = true;
textBox1->Select( 0, textBox1->Text->Length );
// Set the ErrorProvider error with the text to display.
this->errorProvider1->SetError( textBox1, errorMsg );
}
}
void textBox1_Validated( Object^ sender, System::EventArgs^ e )
{
// If all conditions have been met, clear the ErrorProvider of errors.
errorProvider1->SetError( textBox1, "" );
}
public:
bool ValidEmailAddress( String^ emailAddress, [Out]interior_ptr<String^> errorMessage )
{
// Confirm that the e-mail address String* is not empty.
if ( emailAddress->Length == 0 )
{
*errorMessage = "e-mail address is required.";
return false;
}
// Confirm that there is an "@" and a "." in the e-mail address, and in the correct order.
if ( emailAddress->IndexOf( "@" ) > -1 )
{
if ( emailAddress->IndexOf( ".", emailAddress->IndexOf( "@" ) ) > emailAddress->IndexOf( "@" ) )
{
*errorMessage = "";
return true;
}
}
*errorMessage = "e-mail address must be valid e-mail address format.\n" +
"For example 'someone@example.com' ";
return false;
}
private void textBox1_Validating(Object sender,
System.ComponentModel.CancelEventArgs e)
{
String errorMsg = "";
if (!(ValidEmailAddress(textBox1.get_Text(), errorMsg))) {
// Cancel the event and select the text to be corrected by the user.
e.set_Cancel(true);
textBox1.Select(0, textBox1.get_Text().get_Length());
// Set the ErrorProvider error with the text to display.
this.errorProvider1.SetError(textBox1, errorMsg);
}
} //textBox1_Validating
private void textBox1_Validated(Object sender, System.EventArgs e)
{
// If all conditions have been met, clear the ErrorProvider of errors.
errorProvider1.SetError(textBox1, "");
} //textBox1_Validated
public boolean ValidEmailAddress(String emailAddress,
/** @ref
*/ String errorMessage)
{
// Confirm that the e-mail address string is not empty.
if (emailAddress.get_Length() == 0) {
errorMessage = "e-mail address is required.";
return false;
}
// Confirm that there is an "@" and a "." in the e-mail address,
// and in the correct order.
if (emailAddress.IndexOf("@") > -1) {
if (emailAddress.IndexOf(".",
emailAddress.IndexOf("@")) > emailAddress.IndexOf("@")) {
errorMessage = "";
return true;
}
}
errorMessage = "e-mail address must be valid e-mail address format.\n"
+ "For example 'someone@example.com' ";
return false;
} //ValidEmailAddress
플랫폼
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에서 지원
.NET Compact Framework
2.0, 1.0에서 지원
참고 항목
참조
Control 클래스
Control 멤버
System.Windows.Forms 네임스페이스
OnValidated
Control.CausesValidation 속성
Validating