Control.TextChanged イベント

定義

Text プロパティの値が変化すると発生します。

C#
public event EventHandler TextChanged;
C#
public event EventHandler? TextChanged;

イベントの種類

EventHandler

次のコード例では、表示する ForeColor 通貨データを TextBox 変更します。 次の使用例は、テキストを 10 進数に変換し、数値が負の場合と数値が正の場合にColor.Black変更ForeColorColor.Redします。 この例では、FormTextBox.

C#
private void currencyTextBox_TextChanged(object sender, EventArgs e)
{
   try
   {
      // Convert the text to a Double and determine if it is a negative number.
      if(double.Parse(currencyTextBox.Text) < 0)
      {
         // If the number is negative, display it in Red.
         currencyTextBox.ForeColor = Color.Red;
      }
      else
      {
         // If the number is not negative, display it in Black.
         currencyTextBox.ForeColor = Color.Black;
      }
   }
   catch
   {
      // If there is an error, display the text using the system colors.
      currencyTextBox.ForeColor = SystemColors.ControlText;
   }
}

注釈

このイベントは、プログラムによる Text 変更またはユーザー操作によってプロパティが変更された場合に発生します。

イベントの処理の詳細については、「処理とイベントの発生」を参照してください。

適用対象

製品 バージョン
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

こちらもご覧ください