영어로 읽기

다음을 통해 공유


Control.ForeColorChanged 이벤트

정의

ForeColor 속성 값이 변경되면 발생합니다.

public event EventHandler ForeColorChanged;
public event EventHandler? ForeColorChanged;

이벤트 유형

EventHandler

예제

다음 코드 예제는 속성 값이 변경될 때 Text 실행되는 이벤트 처리기입니다. 클래스에는 해당 PropertyName 값이 변경될 때 발생하는 이름 패턴 PropertyNameChanged이 있는 여러 메서드가 있습니다(PropertyName 은 해당 속성의 이름을 나타냅니다).Control

다음 코드 예제에서는 표시되는 통화 데이터의 변경 ForeColor TextBox 내용입니다. 이 예제에서는 텍스트를 10진수로 변환하고 숫자가 음수인지와 숫자가 양수인지로 Color.Black 변경 ForeColor Color.Red 합니다. 이 예제를 Form 사용하려면 .가 포함된 항목이 있어야 합니다 TextBox.

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

설명

이 이벤트는 프로그래밍 방식으로 수정하거나 상호 작용을 통해 속성을 변경하는 경우 ForeColor 발생합니다.

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.

적용 대상

추가 정보