Control.TextChanged イベント
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Public Event TextChanged As EventHandler
public event EventHandler TextChanged
public: event EventHandler^ TextChanged { void add (EventHandler^ value); void remove (EventHandler^ value); }
/** @event */ public void add_TextChanged (EventHandler value) /** @event */ public void remove_TextChanged (EventHandler value)


通貨型のデータを表示する TextBox の ForeColor を変更するコード例を次に示します。テキストを 10 進数に変換し、値が負の場合は ForeColor を Color.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
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: 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; } }
private void currencyTextBox_TextChanged(Object sender, EventArgs e) { try { // Convert the text to a Double and determine if it is a // negative number. if (System.Double.Parse(currencyTextBox.get_Text()) < 0) { // If the number is negative, display it in Red. currencyTextBox.set_ForeColor(Color.get_Red()); } else { // If the number is not negative, display it in Black. currencyTextBox.set_ForeColor(Color.get_Black()); } } catch (System.Exception exp) { // If there is an error, display the text using the system colors. currencyTextBox.set_ForeColor(SystemColors.get_ControlText()); } } //currencyTextBox_TextChanged

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からControl.TextChanged イベントを検索する場合は、下記のリンクをクリックしてください。

- Control.TextChanged イベントのページへのリンク