この記事は翻訳者によって翻訳されたものです。 記事の文章にポインターを重ねると、原文のテキストが表示されます。 |
訳文
原文
|
Control.BackColorChanged イベント
.NET Framework 4
BackColor プロパティの値が変更された場合に発生します。
アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)
Text プロパティの値が変更されたときに実行されるイベント ハンドラーのコード例を次に示します。 Control クラスには、PropertyNameChanged という名前のパターンを持つメソッドがいくつかあります。これらは、対応する PropertyName の値が変更されたときに生成されます。ここで、PropertyName は対応するプロパティの名前を表します。
通貨型のデータを表示する TextBox の ForeColor を変更するコード例を次に示します。 テキストを 10 進数に変換し、値が負の場合は ForeColor を Color.Red に変更し、正の場合は Color.Black に変更する例を次に示します。 この例では、TextBox を格納する Form が存在している必要があります。
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; } }
Windows 7, Windows Vista SP1 以降, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core はサポート対象外), Windows Server 2008 R2 (SP1 以降で Server Core をサポート), Windows Server 2003 SP2
.NET Framework では、各プラットフォームのすべてのバージョンはサポートしていません。 サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。