how can i change the textcolor of the datetime picker from code?

According to MSDN :

Setting the BackColor has no effect on the appearance of the DateTimePicker.

You need to write a custom control that extends DateTimePicker. Override the BackColor property and the WndProc method.

Whenever you change the BackColor, don't forget to call the myDTPicker.Invalidate() method. This will force the control to redrawn using the new color specified.

const int WM_ERASEBKGND = 0x14;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
     if(m.Msg == WM_ERASEBKGND)
     {
       Graphics g = Graphics.FromHdc(m.WParam);
       g.FillRectangle(new SolidBrush(_backColor), ClientRectangle);
       g.Dispose();
       return;
     }

     base.WndProc(ref m);
}

Here is another example of chnaging backColor to dtp: http://www.codeproject.com/KB/selection/DateTimePicker_With_BackC.aspx

Edited 5 Years Ago by Mitja Bonca: n/a

In addition to Mitja Bonca

dateTimePicker1.CalendarForeColor = Color.Red;// will change the fore color of the calender in the datetimepicker, 
 dateTimePicker1.CalendarTitleForeColor=Color.Red; // will change the color of title

Edited 5 Years Ago by abelLazm: n/a

I have Windows 7 and i tried these before posting here
dateTimePicker1.CalendarForeColor = Color.Red;// will change the fore color of the calender in the datetimepicker, dateTimePicker1.CalendarTitleForeColor=Color.Red; // will change the color of titledateTimePicker1.CalendarForeColor = Color.Red;// will change the fore color of the calender in the datetimepicker,
dateTimePicker1.CalendarTitleForeColor=Color.Red; // will change the color of title

but still didn't work now i will try like the other guy told me

This article has been dead for over six months. Start a new discussion instead.