HOW TO:變更 Windows Form MonthCalendar 控制項的外觀
更新:2007 年 11 月
Windows Form MonthCalendar 控制項允許您以各種不同的方式自訂月曆的外觀。例如,您可以設定色彩配置並選擇要顯示或隱藏週數和目前的日期。
若要變更月曆的色彩配置
設定 TitleBackColor、TitleForeColor 和 TrailingForeColor 等屬性。TitleBackColor 屬性也可決定星期天數的字型色彩。TrailingForeColor 屬性決定顯示月份之前和之後日期的色彩。
MonthCalendar1.TitleBackColor = System.Drawing.Color.Blue MonthCalendar1.TrailingForeColor = System.Drawing.Color.Red MonthCalendar1.TitleForeColor = System.Drawing.Color.Yellow
monthCalendar1.TitleBackColor = System.Drawing.Color.Blue; monthCalendar1.TrailingForeColor = System.Drawing.Color.Red; monthCalendar1.TitleForeColor = System.Drawing.Color.Yellow;
monthCalendar1.set_TitleBackColor(System.Drawing.Color.get_Blue()); monthCalendar1.set_TrailingForeColor(System.Drawing.Color.get_Red()); monthCalendar1.set_TitleForeColor(System.Drawing.Color.get_Yellow());
monthCalendar1->TitleBackColor = System::Drawing::Color::Blue; monthCalendar1->TrailingForeColor = System::Drawing::Color::Red; monthCalendar1->TitleForeColor = System::Drawing::Color::Yellow;
若要在控制項下方顯示目前日期
將 ShowToday 屬性設定為 true。當按兩下表單時,以下範例將在顯示和省略今天日期之間切換。
Private Sub Form1_DoubleClick(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.DoubleClick ' Toggle between True and False. MonthCalendar1.ShowToday = Not MonthCalendar1.ShowToday End Sub
private void Form1_DoubleClick(object sender, System.EventArgs e) { // Toggle between True and False. monthCalendar1.ShowToday = !monthCalendar1.ShowToday; }
private void Form1_DoubleClick(System.Object sender, System.EventArgs e) { // Toggle between True and False. monthCalendar1.set_ShowToday(!monthCalendar1.get_ShowToday()); } //Form1_DoubleClick
private: System::Void Form1_DoubleClick(System::Object ^ sender, System::EventArgs ^ e) { // Toggle between True and False. monthCalendar1->ShowToday = !monthCalendar1->ShowToday; }
(Visual C#、Visual C++) 將下列程式碼加入表單的建構函式以註冊事件處理常式。
this.DoubleClick += new System.EventHandler(this.Form1_DoubleClick);
this->DoubleClick += gcnew System::EventHandler(this, &Form1::Form1_DoubleClick);
若要顯示週數
將 ShowWeekNumbers 屬性設定為 true。您可以用程式碼或在 [屬性] 視窗中設定這項屬性。
週數會顯示在每週第一天左方個別的行中。
MonthCalendar1.ShowWeekNumbers = True
monthCalendar1.ShowWeekNumbers = true;
monthCalendar1.set_ShowWeekNumbers(true);
monthCalendar1->ShowWeekNumbers = true;
請參閱
工作
HOW TO:在 Windows Form 的 MonthCalendar 控制項中選取一個日期範圍
HOW TO:使用 Windows Form MonthCalendar 控制項以粗體顯示特定日期
HOW TO:在 Windows Form MonthCalendar 控制項中顯示多個月份