Reputation: 77
Is it possible to change the color of dateTimePicker
if I change date in Calendar?
Upvotes: 2
Views: 14007
Reputation: 324
Maybe not a direct answer (certainly a belated one):
I always take the DateTimePicker control and place it docked (fill) inside a Panel. I make sure the panel has at least a padding of 1 (on all sides). Then, if I need to change the background color or to simulate a border color change, I do it on the surrounding panel instead of the DateTimePicker control directly.
My use case is to simulate when the control is invalid, i.e. put a Color.Red border on the surrounding panel if the date field in question is required.
Upvotes: 3
Reputation: 1943
There is not a property for changing Backgroundcolor
change property but There are several properties that allows you to customize the appearance and behavior of the DateTimePicker control.
If you are using Windows Vista or Windows 7 and using themes such as Aero, then the properties that modifies the color of the calendar has no effect. To see the results of changing the colors of the calendar, we need to disable Visual Styles. For the sake of demonstration, we will do just that. Find Program.cs
in the solution explorer and open it by double clicking it. Comment out or delete the line:
Application.EnableVisualStyles();
For more information use this The DateTimePicker Control
Upvotes: 2
Reputation: 98750
You didn't show any effort but..
DateTimePicker
class has ValueChanged
event that occurs when the Value
property changes.
It is not clear which color that you want to change but you can use CalendarMonthBackground
or CalendarForeColor
properties that you can use with it.
private void DateTimePicker1_ValueChanged(Object sender, EventArgs e)
{
//
}
Looks like changing BackColor
or ForeColor
properties has no effect on current control. In such a case, general recommendation is like; you have to render it yourself and this can be really hard. Solution on Changing the background color of a DateTimePicker in .NET probably will not work either.
Also there is thread on MSDN forum that uses a custom control inherited from DateTimePicker
.
Upvotes: 0