Control.Validating イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Control.Validating イベントの意味・解説 

Control.Validating イベント

コントロール検証行っているときに発生します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Event Validating As
 CancelEventHandler
Dim instance As Control
Dim handler As CancelEventHandler

AddHandler instance.Validating, handler
public event CancelEventHandler Validating
public:
event CancelEventHandler^ Validating {
    void add (CancelEventHandler^ value);
    void remove (CancelEventHandler^ value);
}
/** @event */
public void add_Validating (CancelEventHandler
 value)

/** @event */
public void remove_Validating (CancelEventHandler
 value)
JScript では、イベント使用できますが、新規に宣言することはできません。
解説解説

キーボード (TabShift + 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設定されている場合Validating イベントおよび Validated イベント発生しません。

Validating イベント デリゲートで CancelEventArgs の Cancel プロパティ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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Control.Validating イベント」の関連用語

Control.Validating イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Control.Validating イベントのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS