Share via


Control.ForeColor 속성

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

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public Overridable Property ForeColor As Color
‘사용 방법
Dim instance As Control
Dim value As Color

value = instance.ForeColor

instance.ForeColor = value
public virtual Color ForeColor { get; set; }
public:
virtual property Color ForeColor {
    Color get ();
    void set (Color value);
}
/** @property */
public Color get_ForeColor ()

/** @property */
public void set_ForeColor (Color value)
public function get ForeColor () : Color

public function set ForeColor (value : Color)

속성 값

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

설명

ForeColor 속성은 앰비언트 속성입니다. 앰비언트 속성은 컨트롤 속성으로, 설정되지 않은 경우에는 부모 컨트롤에서 해당 속성을 가져옵니다. 예를 들어, Button은 기본적으로 자신의 부모 Form과 같은 BackColor를 갖습니다. 앰비언트 속성에 대한 자세한 내용은 AmbientProperties 클래스 또는 Control 클래스 개요를 참조하십시오.

상속자 참고 사항 파생 클래스에서 ForeColor 속성을 재정의하는 경우 기본 클래스의 ForeColor 속성을 사용하여 기본 구현을 확장합니다. 그렇지 않으면 모든 구현을 제공해야 합니다. ForeColor 속성의 getset 접근자를 모두 재정의할 필요는 없습니다. 필요에 따라 하나의 접근자만 재정의하면 됩니다.

예제

다음 코드 예제에서는 컨트롤의 BackColorForeColor를 기본 시스템 색상으로 설정합니다. 이 코드는 컨트롤에 자식 컨트롤이 있는 경우 자신을 재귀적으로 호출합니다. 이 코드 예제를 실행하려면 하나 이상의 자식 컨트롤을 갖는 Form이 있어야 합니다. 그러나 이러한 재귀를 보다 잘 보여 주는 예는 Panel 또는 GroupBox와 같이 자식 컨트롤을 갖는 자식 컨테이너 컨트롤입니다.

' 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 Me.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
// 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(this.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:
   void ResetAllControlsBackColor( Control^ control )
   {
      control->BackColor = SystemColors::Control;
      control->ForeColor = SystemColors::ControlText;
      if ( this->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.set_BackColor(SystemColors.get_Control());
    control.set_ForeColor(SystemColors.get_ControlText());
    if (this.get_HasChildren()) {
        for (int iCtr=0; iCtr < control.get_Controls().get_Count(); iCtr++) {
            // Recursively call this method for each child control.
            Control childControl = control.get_Controls().get_Item(iCtr);
            ResetAllControlsBackColor(childControl);
        }
    }
} //ResetAllControlsBackColor

플랫폼

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에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Control 클래스
Control 멤버
System.Windows.Forms 네임스페이스
ForeColorChanged
OnForeColorChanged
Color