Changing the Windows Forms MonthCalendar Control's Appearance

Changing the Windows Forms MonthCalendar Control's Appearance

Visual Studio .NET 2003

The Windows Forms MonthCalendar control allows you to customize its appearance in many ways. Possibilities include the color scheme and choosing to display or hide week numbers and the current date.

To change the month calendar's color scheme

  • Set properties such as TitleBackColor, TitleForeColor and TrailingForeColor. The TitleBackColor property also determines the font color for the days of the week. The TrailingForeColor property determines the color of the dates that precede and follow the displayed month or months.
    ' Visual Basic
    MonthCalendar1.TitleBackColor = System.Drawing.Color.Blue
    MonthCalendar1.TrailingForeColor = System.Drawing.Color.Red
    MonthCalendar1.TitleForeColor = System.Drawing.Color.Yellow
    
    // C#
    monthCalendar1.TitleBackColor = System.Drawing.Color.Blue;
    monthCalendar1.TrailingForeColor = System.Drawing.Color.Red;
    monthCalendar1.TitleForeColor = System.Drawing.Color.Yellow;
    
    // C++
    monthCalendar1->TitleBackColor = System::Drawing::Color::Blue;
    monthCalendar1->TrailingForeColor = System::Drawing::Color::Red;
    monthCalendar1->TitleForeColor = System::Drawing::Color::Yellow;
    

To display the current date at the bottom of the control

  • Set the ShowToday property to true. The example below toggles between displaying and omitting today's date when the form is double-clicked.
    ' Visual Basic
    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
    
    // C#
    private void Form1_DoubleClick(object sender, System.EventArgs e)
    {
       // Toggle between True and False.
       monthCalendar1.ShowToday = !monthCalendar1.ShowToday;
    }
    
    // C++
    private:
       System::Void Form1_DoubleClick(System::Object *  sender,
          System::EventArgs *  e)
       {
          // Toggle between True and False.
          monthCalendar1->ShowToday = !monthCalendar1->ShowToday;
       }
    
    Visual C# and Visual C++ Note   Be sure that the necessary code to enable the event handler is present. In this case, it would be similar to the following:
    // C#
    this.DoubleClick += new System.EventHandler(this.Form1_DoubleClick);
    // C++
    this->DoubleClick += new System::EventHandler(this,
    Form1_DoubleClick);

To display week numbers

  • Set the ShowWeekNumbers property to true. You can set this property either in code, or in the Properties window.

    Week numbers appear in a separate column to the left of the first day of the week.

    ' Visual Basic
    MonthCalendar1.ShowWeekNumbers = True
    
    // C#
    monthCalendar1.ShowWeekNumbers = true;
    
    // C++
    monthCalendar1->ShowWeekNumbers = true;
    

See Also

MonthCalendar Control (Windows Forms) | Selecting a Range of Dates in the Windows Forms MonthCalendar Control | Displaying Specific Days in Bold with the Windows Forms MonthCalendar Control | Displaying More than One Month in the Windows Forms MonthCalendar Control

Show:
© 2016 Microsoft