MonthCalendar.BackColor 屬性

定義

取得或設定控制項的背景色彩。

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

屬性值

Color

Color ,代表控制項的背景色彩。 預設值為 DefaultBackColor 屬性的值。

範例

下列程式碼範例會將 BackColor 控制項的 和 ForeColor 設定為預設系統色彩。 如果控制項有任何子控制項,程式碼會以遞迴方式呼叫本身。 此程式碼範例需要您具有 Form 至少一個子控制項的 ;不過,子容器控制項,例如 PanelGroupBox ,其本身的子控制項 () 會更能示範遞迴。

   // 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

備註

除非 BackColor 的值 System.Windows.Forms.ControlStyles 設定 true 為 ,否則 SupportsTransparentBackColor 屬性不支援透明色彩。

屬性 BackColor 是環境屬性。 環境屬性是控制項屬性,如果未設定,則會從父控制項擷取。 例如, Button 預設會有與其父系 Form 相同的 BackColor 。 如需環境屬性的詳細資訊,請參閱 AmbientProperties 類別或 Control 類別概觀。

從 Windows Vista 開始,並根據主題而定,設定此屬性可能不會變更行事曆的外觀。 例如,如果Windows設定為使用[Windows] 主題,則設定此屬性不會有任何作用。 這是因為行事曆的更新版本會以從目前的作業系統主題在執行時間衍生的外觀來轉譯。 如果您想要使用這個屬性並啟用舊版的行事曆,您可以停用應用程式的視覺化樣式。 停用視覺樣式可能會影響應用程式中其他控制項的外觀和行為。 若要停用Visual Basic中的視覺化樣式,請開啟 [Project設計工具],然後取消核取 [啟用 XP 視覺效果樣式] 核取方塊。 若要停用 C# 中的視覺化樣式,請開啟 Program.cs 並批註化 Application.EnableVisualStyles();

給繼承者的注意事項

在衍生類別中覆 BackColor 寫屬性時,請使用基類的 BackColor 屬性來擴充基底實作。 否則,您必須提供所有實作。 您不需要同時覆寫 get 屬性的 BackColorset 存取子;您可以視需要只覆寫一個。

適用於

另請參閱