The DateTimePicker ValueChanged event fires for the first time when there are no changes

Winforms 2.0. Attach DateTimePicker to the form. It is by default TODAY. Click the down arrow to display the calendar, and click "TODAY." The ValueChanged event does FIRE, even if it is already set today.

What I would like to do is replicate the same functionality - I would like to reset it (in code) today, and the next time I click on today via Calendar, I want the ValueChanged event to fire (as he did the first time).

If this is not possible, I want some kind of event to always fire when I select a date on the calendar (regardless of whether there is a change or not changes).

It sounds very simple, surely someone has an answer?

+3
source share
2 answers

What you see is a side effect of the fact that DateTimePicker stores the time component of its value, as well as the date.

So, when your form is initialized first, DateTimePicker is initialized to DateTime.Now. When you select Today from the drop-down calendar, you change the value to DateTime.Today.

/ dateTimePicker1.Value.Date, DateTime.Now, ValueChanged , . CloseUp, , ( , ).

+6

, , Day_Render. ... , -, , . Render().

0

Source: https://habr.com/ru/post/1719850/


All Articles