Control.BackgroundImageChanged イベント

BackgroundImage プロパティの値が変更された場合に発生します。

Public Event BackgroundImageChanged As EventHandler
[C#]
public event EventHandler BackgroundImageChanged;
[C++]
public: __event EventHandler* BackgroundImageChanged;

[JScript] JScript では、このクラスで定義されているイベントを処理できます。ただし、独自に定義することはできません。

イベント データ

イベント ハンドラが EventArgs 型の引数を受け取りました。

解説

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

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

使用例

[Visual Basic, C#, C++] この例は、 Text プロパティの値が変更されたときに実行されるイベント処理メソッドです。 Control クラスには、PropertyName Changed という名前のパターンを持つメソッドがいくつかあります。これらは、対応する PropertyName の値が変更されたときに生成されます。ここで、PropertyName は対応するプロパティの名前を表します。

[Visual Basic, C#, C++] 通貨型のデータを表示する TextBoxForeColor を変更する例を次に示します。テキストを 10 進数に変換し、値が負の場合は ForeColorColor.Red に変更し、正の場合は Color.Black に変更する例を次に示します。この例は、 TextBox が配置された Form があることを前提にしています。

 
Private Sub currencyTextBox_TextChanged(sender As Object, _ 
  e As EventArgs) Handles currencyTextBox.TextChanged
   Try
      ' Convert the text to a Double and determine if it is a negative number.
      If Double.Parse(currencyTextBox.Text) < 0 Then
         ' 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
      End If
   Catch
      ' If there is an error, display the text using the system colors.
      currencyTextBox.ForeColor = SystemColors.ControlText
   End Try
End Sub 

[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;
   }
}

[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 (Exception*) {
            // If there is an error, display the text using the system colors.
            currencyTextBox->ForeColor = SystemColors::ControlText;
        }
    }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Control クラス | Control メンバ | System.Windows.Forms 名前空間 | BackgroundImage | OnBackgroundImageChanged | Image