It is necessary that when selecting a specific date, a message would be displayed via if, for example, if 2018, 12, 19 is selected to display the word Holiday

private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { dateTimePicker1.MinDate = new DateTime(1985, 6, 20); dateTimePicker1.MaxDate = DateTime.Today; //if (dateTimePicker1.Value = 2018 , 12, 18) { MessageBox.Show("Holliday"); } } 
  • Well, what type of dateTimePicker1.Value ? Right, DateTime . What do we compare values ​​with? With an object of the same type. How is the comparison going? Two characters equals ( == ). Based on this, what conclusion do we come to? - EvgeniyZ
  • EvgeniyZ if (dateTimePicker1.Value == new DateTime (2018, 12, 18)) right? - lamer
  • one
    And what prevents to check?) After all, you will not at every "sneeze" ask for help from passersby. Try it, nothing bad will happen! - EvgeniyZ
  • Compiles fine, but MessageBox does not appear when this date is selected - lamer
  • 2
    The next step is debugging. Put a stopping point on the if line and see what it equals Value, is it equal to the date you specified? I will say right away, most likely not, because you choose the number 18 when you limit the range of dates to the current (16) and because of this, after the line dateTimePicker1.MaxDate = DateTime.Today; The control will not accept the date higher than the current, choosing instead the last available (16). By the way, such a restriction in the event does not make sense, it is enough to register in the constructor, or once during the form initialization (for example). - EvgeniyZ

0