Just start a new Windows Forms Application and change the Form1 constructor to this code(which was copied from MSDN)

public Form1()
        {
            InitializeComponent();
            // Create the calendar.
            MonthCalendar monthCalendar2 = new System.Windows.Forms.MonthCalendar();

            // Set the calendar location.
            monthCalendar2.Location = new System.Drawing.Point(50, 50);

            // Change the color.
            monthCalendar2.BackColor = System.Drawing.SystemColors.Info;
            monthCalendar2.ForeColor = System.Drawing.Color.FromArgb(
                                     ((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(192)));
            monthCalendar2.TitleBackColor = System.Drawing.Color.Purple;
            monthCalendar2.TitleForeColor = System.Drawing.Color.Yellow;
            monthCalendar2.TrailingForeColor = System.Drawing.Color.FromArgb(
                                     ((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(0)));

            // Do not show the "Today" banner.
            monthCalendar2.ShowToday = false;

            // Do not circle today's date.
            monthCalendar2.ShowTodayCircle = false;

            this.Controls.Add(monthCalendar2);
        }

My problem is that the color changes don't show and I wonder why.
I feel like I'm omitting something, but having searched here, there and everywhere I am stuck. Is it my OS?(Vista)
Thanks in advance for any enlightment on this.:S

Dani AI

Generated

Short summary and extra options (builds on , and )

As explained, this is not a bug in the property assignments but a consequence of Windows visual styles: the MonthCalendar is a native common control that the OS theme engine draws when themes/visual styles are enabled, and the themed drawing ignores BackColor/TitleBackColor/TrailingForeColor, etc. Those properties take effect only when the control is not themed.

Useful options and practical notes

  • Global: disable visual styles for the whole app (project setting or stop calling Application.EnableVisualStyles()). This reproduces the classic rendering so the color properties work (what and suggested).

  • Per-control (recommended when the rest of the UI should stay themed): turn off theming just for the calendar by calling SetWindowTheme on the control’s handle. This removes theme rendering for that control only, allowing the color properties to be honored. Example P/Invoke (call after the control’s handle exists, e.g. in Form.Load):

[System.Runtime.InteropServices.DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
private static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList);

// then, after InitializeComponent / in Form.Load:
SetWindowTheme(monthCalendar1.Handle, "", "");
// set color properties and Refresh() afterwards
  • Replace: if themed appearance must be preserved while also needing custom colors/behavior, use a custom-drawn calendar or a third-party control that supports theming and color customization.

Troubleshooting tips

Ensure SetWindowTheme is invoked after the control’s handle is created (Control.IsHandleCreated or in Load). If changes still don’t appear, call Refresh() or recreate the control. For long-term maintenance, prefer the per-control theming approach to avoid losing visual styles across the whole application.

Recommended Answers

All 4 Replies

Yes, Danny, it's Vista problem (Aero, and Vista basic) color scheme, if you turn it into Windows Classic it'd work.

Or, remove Vista style

[STAThread]
        static void Main()
        {
            //Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
commented: Offered a plethora of solutions to the problem! +4

Thanks Ramy!
I indeed have Vista Basic.
Your suggestions all work, so I consider this as solved.
Thanks again!

For this problem you can disable visual styles for your application through properties of your application.

read this article about how to change appearance of month calendar and how to disable Visual style of application:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.