Control.ForeColor 속성

정의

컨트롤의 전경색을 가져오거나 설정합니다.

public:
 virtual property System::Drawing::Color ForeColor { System::Drawing::Color get(); void set(System::Drawing::Color value); };
public virtual System.Drawing.Color ForeColor { get; set; }
member this.ForeColor : System.Drawing.Color with get, set
Public Overridable Property ForeColor As Color

속성 값

Color

컨트롤의 전경 Color입니다. 기본값은 DefaultForeColor 속성 값입니다.

예제

다음 코드 예제에서는 컨트롤을 BackColor ForeColor 기본 시스템 색으로 설정합니다. 컨트롤에 자식 컨트롤이 있는 경우 코드가 재귀적으로 자신을 호출합니다. 이 코드 예제 Form 에서는 자식 컨트롤이 하나 이상 있어야 합니다. 그러나 자식 컨트롤이 있는 GroupBox자식 컨테이너 컨트롤(예: Panel 자식 컨트롤)은 재귀를 더 잘 보여 줍니다.

   // Reset all the controls to the user's default Control color.
private:
   void ResetAllControlsBackColor( Control^ control )
   {
      control->BackColor = SystemColors::Control;
      control->ForeColor = SystemColors::ControlText;
      if ( control->HasChildren )
      {
         // Recursively call this method for each child control.
         IEnumerator^ myEnum = control->Controls->GetEnumerator();
         while ( myEnum->MoveNext() )
         {
            Control^ childControl = safe_cast<Control^>(myEnum->Current);
            ResetAllControlsBackColor( childControl );
         }
      }
   }
// Reset all the controls to the user's default Control color. 
private void ResetAllControlsBackColor(Control control)
{
   control.BackColor = SystemColors.Control;
   control.ForeColor = SystemColors.ControlText;
   if(control.HasChildren)
   {
      // Recursively call this method for each child control.
      foreach(Control childControl in control.Controls)
      {
         ResetAllControlsBackColor(childControl);
      }
   }
}
' Reset all the controls to the user's default Control color. 
Private Sub ResetAllControlsBackColor(control As Control)
   control.BackColor = SystemColors.Control
   control.ForeColor = SystemColors.ControlText
   If control.HasChildren Then
      ' Recursively call this method for each child control.
      Dim childControl As Control
      For Each childControl In  control.Controls
         ResetAllControlsBackColor(childControl)
      Next childControl
   End If
End Sub

설명

ForeColor 속성은 앰비언트 속성입니다. 앰비언트 속성은 설정되지 않은 경우 부모 컨트롤에서 검색되는 컨트롤 속성입니다. 예를 들어 a는 Button 기본적으로 부모와 Form 동일합니다BackColor. 앰비언트 속성에 대한 자세한 내용은 클래스 또는 클래스 개요를 Control 참조 AmbientProperties 하세요.

상속자 참고

파생 클래스에서 ForeColor 속성을 재정의할 때 기본 클래스의 ForeColor 속성을 사용하여 기본 구현을 확장합니다. 그렇지 않으면 모든 구현을 제공해야 합니다. 속성의 접근자와 set 접근자를 모두 get 재정의할 필요는 없습니다. 필요한 경우 하나만 재정의 ForeColor 할 수 있습니다.

적용 대상

추가 정보