Control.BackColorChanged イベント
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
BackColor プロパティの値が変化したときに発生します。
public:
event EventHandler ^ BackColorChanged;
C#
public event EventHandler BackColorChanged;
C#
public event EventHandler? BackColorChanged;
member this.BackColorChanged : EventHandler
Public Custom Event BackColorChanged As EventHandler
次のコード例は、プロパティ値が変更されたときに Text 実行されるイベント ハンドラーです。 このControlクラスには、対応する PropertyName 値が変更されたときに発生する名前パターン PropertyNameChanged
を持ついくつかのメソッドがあります (PropertyName は、対応するプロパティの名前を表します)。
次のコード例では、表示する ForeColor 通貨データを TextBox 変更します。 次の使用例は、テキストを 10 進数に変換し、数値が負の場合と数値が正の場合にColor.Black変更ForeColorColor.Redします。 この例では、FormTextBox.
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;
}
}
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;
}
}
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
このイベントは、プログラムによる 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 |