Control.BackColorChanged イベント

定義

BackColor プロパティの値が変化したときに発生します。

C#
public event EventHandler BackColorChanged;
C#
public event EventHandler? BackColorChanged;

イベントの種類

EventHandler

次のコード例は、プロパティ値が変更されたときに Text 実行されるイベント ハンドラーです。 このControlクラスには、対応する PropertyName 値が変更されたときに発生する名前パターン PropertyNameChanged を持ついくつかのメソッドがあります (PropertyName は、対応するプロパティの名前を表します)。

次のコード例では、表示する 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;
   }
}

注釈

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

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

適用対象

製品 バージョン
.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

こちらもご覧ください