Control.CausesValidation プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Control.CausesValidation プロパティの意味・解説 

Control.CausesValidation プロパティ

そのコントロール原因で、フォーカス受け取ると検証必要なコントロールに対して検証実行されるかどうかを示す値を取得または設定します

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

Public Property CausesValidation As
 Boolean
Dim instance As Control
Dim value As Boolean

value = instance.CausesValidation

instance.CausesValidation = value
public bool CausesValidation { get;
 set; }
public:
property bool CausesValidation {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_CausesValidation ()

/** @property */
public void set_CausesValidation (boolean value)
public function get CausesValidation
 () : boolean

public function set CausesValidation
 (value : boolean)

プロパティ
そのコントロール原因で、フォーカス受け取ると検証必要なコントロールに対して検証実行される場合trueそれ以外場合false既定値true です。

解説解説

CausesValidation プロパティfalse設定されている場合、Validating イベントおよび Validated イベント発生しません。

CausesValidation プロパティ値は、通常、[ヘルプ] ボタンなどのコントロールに対して false設定されます。

使用例使用例

テキスト ボックス入力され数値加算する Windows フォーム作成するコード例次に示します結果表示する前にテキスト ボックス検証されます。

Private Sub AddHandlers()
    ' Add the Validating and Validated handlers for textboxes.
    AddHandler myTextBox1.Validating, AddressOf
 myTextBox1_Validating
    AddHandler myTextBox1.Validated, AddressOf
 myTextBox1_Validated
    AddHandler myTextBox2.Validating, AddressOf
 myTextBox2_Validating
    AddHandler myTextBox2.Validated, AddressOf
 myTextBox2_Validated
    AddHandler myTextBox1.CausesValidationChanged, AddressOf
 myTextBox1_CausesValidationChanged
    AddHandler myTextBox2.CausesValidationChanged, AddressOf
 myTextBox2_CausesValidationChanged
    If myTextBox1.CausesValidation = True And
 myTextBox2.CausesValidation = True Then
       button1.Text = "Disable Validation"
       myLabel.Text = "Validation Enabled"
       Me.Focus()
    End If
End Sub 'AddHandlers
 
Private Sub myTextBox1_Validating(sender As
 Object, e As System.ComponentModel.CancelEventArgs)
    If Not CheckIfTextBoxNumeric(myTextBox1)
 Then
       myLabel.Text = "Has to be numeric"
       e.Cancel = True
    End If
End Sub 'myTextBox1_Validating
 
Private Sub myTextBox1_Validated(sender As
 Object, e As System.EventArgs)
    myLabel.Text = "Validated first control"
End Sub 'myTextBox1_Validated
 
Private Sub myTextBox2_Validating(sender As
 Object, e As System.ComponentModel.CancelEventArgs)
    If Not CheckIfTextBoxNumeric(myTextBox2)
 Then
       myLabel.Text = "Has to be numeric"
       e.Cancel = True
    End If
End Sub 'myTextBox2_Validating
 
Private Sub myTextBox2_Validated(sender As
 Object, e As System.EventArgs)
    myLabel.Text = "Validated second control"
End Sub 'myTextBox2_Validated
 
Private Sub myTextBox1_CausesValidationChanged(sender
 As Object, e As System.EventArgs)
    myLabel.Text = "CausesValidation property was changed for
 First Textbox"
End Sub 'myTextBox1_CausesValidationChanged
 
Private Sub myTextBox2_CausesValidationChanged(sender
 As Object, e As System.EventArgs)
    myLabel.Text = "CausesValidation property was changed for
 Second Textbox"
End Sub 'myTextBox2_CausesValidationChanged
 
Private Function CheckIfTextBoxNumeric(myTextBox1
 As TextBox) As Boolean
    Dim isValid As Boolean
 = True
    If myTextBox1.Text = "" Then
       isValid = False
    Else
       Dim i As Integer
       For i = 0 To myTextBox1.Text.Length
 - 1
          If Not IsNumeric(myTextBox1.Text)
 Then
             myTextBox1.Text = ""
             isValid = False
             Exit For
          End If
       Next i
    End If
    Return isValid
End Function 'CheckIfTextBoxNumeric
 
Private Sub myButtonAdd_Click(sender As
 Object, e As System.EventArgs) Handles
 myButtonAdd.Click
   Try
      Dim result As Integer
 = Convert.ToInt32(myTextBox1.Text) + Convert.ToInt32(myTextBox2.Text)
       myLabel.Text = result.ToString()
    Catch myException As Exception
       myLabel.Text = "Exception : " + myException.Message
    End Try
End Sub 'myButtonAdd_Click
 
 
Private Sub button1_Click(sender As
 Object, e As System.EventArgs) Handles
 button1.Click
    If myTextBox1.CausesValidation = False
 And myTextBox2.CausesValidation = False Then
       myTextBox1.CausesValidation = True
       myTextBox2.CausesValidation = True
       button1.Text = "Disable Validation"
       myLabel.Text = "Validation Enabled"
    Else
       If myTextBox1.CausesValidation = True And
 myTextBox2.CausesValidation = True Then
          myTextBox1.CausesValidation = False
          myTextBox2.CausesValidation = False
          button1.Text = "Enable Validation"
          myLabel.Text = "Validation Disabled"
       End If
    End If
End Sub 'button1_Click 
private void AddHandlers()
{
   // Add the Validating and Validated handlers for textboxes.
   myTextBox1.Validating +=
      new System.ComponentModel.CancelEventHandler(myTextBox1_Validating);
   myTextBox1.Validated += 
      new System.EventHandler(myTextBox1_Validated);
   myTextBox2.Validating += 
      new System.ComponentModel.CancelEventHandler(myTextBox2_Validating);
   myTextBox2.Validated += 
      new System.EventHandler(myTextBox2_Validated);
   myTextBox1.CausesValidationChanged += 
      new System.EventHandler(myTextBox1_CausesValidationChanged);
   myTextBox2.CausesValidationChanged += 
      new System.EventHandler(myTextBox2_CausesValidationChanged);
   if(myTextBox1.CausesValidation == true &&
 myTextBox2.CausesValidation == true) 
   {
      button1.Text = "Disable Validation";
      myLabel.Text = "Validation Enabled"; 
      this.Focus(); 
   }
}
private void myTextBox1_Validating(object sender,System.ComponentModel.CancelEventArgs
 e)
{        
   if(!CheckIfTextBoxNumeric(myTextBox1))
   {
      myLabel.Text =  "Has to be numeric";
      e.Cancel = true;
   }
}
private void myTextBox1_Validated(object sender,System.EventArgs
 e)
{
   myLabel.Text = "Validated first control";          
}
private void myTextBox2_Validating(object sender,System.ComponentModel.CancelEventArgs
 e)
{
   if(!CheckIfTextBoxNumeric(myTextBox2))
   {
      myLabel.Text =  "Has to be numeric";
      e.Cancel = true;
   }
}
private void myTextBox2_Validated(object sender,System.EventArgs
 e)
{
   myLabel.Text = "Validated second control";
}
private void myTextBox1_CausesValidationChanged(object
 sender,System.EventArgs e)
{  
   myLabel.Text = "CausesValidation property was changed for
 First Textbox";
}
private void myTextBox2_CausesValidationChanged(object
 sender,System.EventArgs e)
{  
   myLabel.Text = "CausesValidation property was changed for
 Second Textbox";
}
private bool CheckIfTextBoxNumeric(TextBox
 myTextBox1)
{ 
   bool isValid = true;
   if(myTextBox1.Text == "")
   {
      isValid = false;
   }
   else
   {
      for(int i=0; i< myTextBox1.Text.Length;i++)
      {
         if(!(System.Char.IsNumber(myTextBox1.Text[i]))) 
         {
            myTextBox1.Text = ""; 
            isValid = false;
            break;
         }
      }
   }
   return isValid;
}
private void myButtonAdd_Click(object sender,
 System.EventArgs e)
{  
   try
   {
      int result = Convert.ToInt32(myTextBox1.Text) + Convert.ToInt32(myTextBox2.Text);
      myLabel.Text =  result.ToString();
   }
   catch(Exception myException)
   {
      myLabel.Text = "Exception : " + myException.Message;
   }
}

private void button1_Click(object sender, System.EventArgs
 e)
{  
   if(myTextBox1.CausesValidation == false
 && myTextBox2.CausesValidation == false) 
   {
      myTextBox1.CausesValidation = true;
      myTextBox2.CausesValidation = true;
      button1.Text = "Disable Validation"; 
      myLabel.Text = "Validation Enabled"; 
   }
   else if(myTextBox1.CausesValidation == true
 && myTextBox2.CausesValidation == true) 
   {
      myTextBox1.CausesValidation = false;
      myTextBox2.CausesValidation = false;
      button1.Text = "Enable Validation"; 
      myLabel.Text = "Validation Disabled"; 
   }
}
private:
   void AddHandlers()
   {
      
      // Add the Validating and Validated handlers for textboxes.
      myTextBox1->Validating += gcnew System::ComponentModel::CancelEventHandler(
 this, &Form1::myTextBox1_Validating );
      myTextBox1->Validated += gcnew System::EventHandler( this,
 &Form1::myTextBox1_Validated );
      myTextBox2->Validating += gcnew System::ComponentModel::CancelEventHandler(
 this, &Form1::myTextBox2_Validating );
      myTextBox2->Validated += gcnew System::EventHandler( this,
 &Form1::myTextBox2_Validated );
      myTextBox1->CausesValidationChanged += gcnew System::EventHandler( this,
 &Form1::myTextBox1_CausesValidationChanged );
      myTextBox2->CausesValidationChanged += gcnew System::EventHandler( this,
 &Form1::myTextBox2_CausesValidationChanged );
      if ( myTextBox1->CausesValidation == true
 && myTextBox2->CausesValidation == true )
      {
         button1->Text = "Disable Validation";
         myLabel->Text = "Validation Enabled";
         this->Focus();
      }
   }

   void myTextBox1_Validating( Object^ /*sender*/, System::ComponentModel::CancelEventArgs^
 e )
   {
      if (  !CheckIfTextBoxNumeric( myTextBox1 ) )
      {
         myLabel->Text = "Has to be numeric";
         e->Cancel = true;
      }
   }

   void myTextBox1_Validated( Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      myLabel->Text = "Validated first control";
   }

   void myTextBox2_Validating( Object^ /*sender*/, System::ComponentModel::CancelEventArgs^
 e )
   {
      if (  !CheckIfTextBoxNumeric( myTextBox2 ) )
      {
         myLabel->Text = "Has to be numeric";
         e->Cancel = true;
      }
   }

   void myTextBox2_Validated( Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      myLabel->Text = "Validated second control";
   }

   void myTextBox1_CausesValidationChanged( Object^ /*sender*/,
 System::EventArgs^ /*e*/ )
   {
      myLabel->Text = "CausesValidation property was changed for
 First Textbox";
   }

   void myTextBox2_CausesValidationChanged( Object^ /*sender*/,
 System::EventArgs^ /*e*/ )
   {
      myLabel->Text = "CausesValidation property was changed for
 Second Textbox";
   }

   bool CheckIfTextBoxNumeric( TextBox^ myTextBox1 )
   {
      bool isValid = true;
      if ( myTextBox1->Text->Equals( "" ) )
      {
         isValid = false;
      }
      else
      {
         for ( int i = 0; i < myTextBox1->Text->Length;
 i++ )
         {
            if (  !(System::Char::IsNumber( myTextBox1->Text[
 i ] )) )
            {
               myTextBox1->Text = "";
               isValid = false;
               break;
            }

         }
      }

      return isValid;
   }

   void myButtonAdd_Click( Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      try
      {
         int result = Convert::ToInt32( myTextBox1->Text )
 + Convert::ToInt32( myTextBox2->Text );
         myLabel->Text = result.ToString();
      }
      catch ( Exception^ myException ) 
      {
         myLabel->Text = "Exception : ",myException->Message;
      }

   }

   void button1_Click( Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      if ( myTextBox1->CausesValidation == false
 && myTextBox2->CausesValidation == false )
      {
         myTextBox1->CausesValidation = true;
         myTextBox2->CausesValidation = true;
         button1->Text = "Disable Validation";
         myLabel->Text = "Validation Enabled";
      }
      else
      if ( myTextBox1->CausesValidation == true
 && myTextBox2->CausesValidation == true )
      {
         myTextBox1->CausesValidation = false;
         myTextBox2->CausesValidation = false;
         button1->Text = "Enable Validation";
         myLabel->Text = "Validation Disabled";
      }
   }
private void AddHandlers()
{
    // Add the Validating and Validated handlers for textboxes.
    myTextBox1.add_Validating(new System.ComponentModel.
        CancelEventHandler(myTextBox1_Validating));
    myTextBox1.add_Validated(new System.EventHandler(myTextBox1_Validated));
    myTextBox2.add_Validating(new System.ComponentModel.
        CancelEventHandler(myTextBox2_Validating));
    myTextBox2.add_Validated(new System.EventHandler(myTextBox2_Validated));
    myTextBox1.add_CausesValidationChanged(new System.
        EventHandler(myTextBox1_CausesValidationChanged));
    myTextBox2.add_CausesValidationChanged(new System.
        EventHandler(myTextBox2_CausesValidationChanged));
    if (myTextBox1.get_CausesValidation() == true
 && myTextBox2.
        get_CausesValidation() == true) {
        button1.set_Text("Disable Validation");
        myLabel.set_Text("Validation Enabled");
        this.Focus();
    }
} //AddHandlers

private void myTextBox1_Validating(Object sender,
 
    System.ComponentModel.CancelEventArgs e)
{
    if (!(CheckIfTextBoxNumeric(myTextBox1))) {
        myLabel.set_Text("Has to be numeric");
        e.set_Cancel(true);
    }
} //myTextBox1_Validating

private void myTextBox1_Validated(Object sender,
 
    System.EventArgs e)
{
    myLabel.set_Text("Validated first control");
} //myTextBox1_Validated

private void myTextBox2_Validating(Object sender,
 
    System.ComponentModel.CancelEventArgs e)
{
    if (!(CheckIfTextBoxNumeric(myTextBox2))) {
        myLabel.set_Text("Has to be numeric");
        e.set_Cancel(true);
    }
} //myTextBox2_Validating

private void myTextBox2_Validated(Object sender,
 System.EventArgs e)
{
    myLabel.set_Text("Validated second control");
} //myTextBox2_Validated

private void myTextBox1_CausesValidationChanged(Object
 sender, 
    System.EventArgs e)
{
    myLabel.set_Text("CausesValidation property was changed for
 "
        + "First Textbox");
} //myTextBox1_CausesValidationChanged

private void myTextBox2_CausesValidationChanged(Object
 sender, 
    System.EventArgs e)
{
    myLabel.set_Text("CausesValidation property was changed for
 "
        + "Second Textbox");
} //myTextBox2_CausesValidationChanged

private boolean CheckIfTextBoxNumeric(TextBox myTextBox1)
{
    boolean isValid = true;
    if (myTextBox1.get_Text().Equals("")) {
        isValid = false;
    }
    else {
        for (int i = 0; i < myTextBox1.get_Text().get_Length();
 i++) {
            if (!(System.Char.IsNumber(myTextBox1.get_Text().
                get_Chars(i)))) {
                myTextBox1.set_Text("");
                isValid = false;
                break;
            }
        }
    }
    return isValid;
} //CheckIfTextBoxNumeric

private void myButtonAdd_Click(Object sender,
 System.EventArgs e)
{
    try {
        int result = Convert.ToInt32(myTextBox1.get_Text()) 
            + Convert.ToInt32(myTextBox2.get_Text());
        myLabel.set_Text(System.Convert.ToString(result));
    }
    catch (System.Exception myException) {
        myLabel.set_Text("Exception : " + myException.get_Message());
    }
} //myButtonAdd_Click

private void button1_Click(Object sender, System.EventArgs
 e)
{
    if (myTextBox1.get_CausesValidation() == false
 && myTextBox2.
        get_CausesValidation() == false) {
        myTextBox1.set_CausesValidation(true);
        myTextBox2.set_CausesValidation(true);
        button1.set_Text("Disable Validation");
        myLabel.set_Text("Validation Enabled");
    }
    else {
        if (myTextBox1.get_CausesValidation() == true
 && myTextBox2.
            get_CausesValidation() == true) {
            myTextBox1.set_CausesValidation(false);
            myTextBox2.set_CausesValidation(false);
            button1.set_Text("Enable Validation");
            myLabel.set_Text("Validation Disabled");
        }
    }
} //button1_Click
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からControl.CausesValidation プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からControl.CausesValidation プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からControl.CausesValidation プロパティ を検索

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

辞書ショートカット

すべての辞書の索引

「Control.CausesValidation プロパティ」の関連用語

Control.CausesValidation プロパティのお隣キーワード
検索ランキング

   

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



Control.CausesValidation プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS