|
Il presente articolo è stato tradotto automaticamente. Passare il puntatore sulle frasi nell'articolo per visualizzare il testo originale. Ulteriori informazioni.
|
Traduzione
Originale
|
Evento Control.Validating
Spazio dei nomi: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Attenzione |
|---|
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; }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (ruoli di base del server non supportati), Windows Server 2008 R2 (ruoli di base del server supportati con SP1 o versione successiva, Itanium non supportato)
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.
Attenzione