title: Proper way for datepickers validaton in c#? (windows forms)
body: <p>Just can't get it with <code>datepicker</code> validation.
  I have <code>datepicker</code> <strong>From</strong> and <code>datepicker</code> <strong>To</strong>, so I want to prevent the user from doing some kung fu and seting <code>datepicker</code> <strong>From</strong> to be bigger than <code>datepicker</code> <strong>To</strong>, I've bumped across some <a href="https://stackoverflow.com/questions/18738498/date-time-picker-validations">questions</a> but couldn't find the answer, so I've tried doing the easiest way I could think of:</p>
  
  <p>Set <code>MaxDate</code> property for <code>datepicker</code> <strong>from</strong> in <code>form_load</code> event</p>
  
  <pre><code>private void Form1_Load(object sender, EventArgs e)
  {
       datepickerFrom.MaxDate = datepickerFrom.Value;
  }
  </code></pre>
  
  <p>Then do the same for <code>value_changed</code> event </p>
  
  <pre><code>private void datepickerFrom_ValueChanged(object sender, EventArgs e)
  {
      datepickerFrom.MaxDate = datepickerFrom.Value;
  }
  </code></pre>
  
  <p>This was easy and fine, only few lines of code, and I've only needed <code>datepickerFrom_ValueChanged</code> event, but recently I've tried <strong>typing</strong> date into <code>datepicker</code> insted of selecting it, and then all hell broke loose.
  So I came to some solution for validation, instead of setting <code>MaxDate</code> property, I've tried this.</p>
  
  <pre><code>private void dtFrom_ValueChanged(object sender, EventArgs e)
  {        
      DateTime from = datepickerFrom.Value;
      DateTime to = datepickerTo.Value;
      int year= from.Year &gt; to.Year ? to.Year : from.Year;
      int month = from.Month &gt; to.Month ? to.Month : from.Month;
      int day = from.Day &gt; to.Day ? to.Day : from.Day;
      int hour = from.Hour &gt; to.Hour ? to.Hour : from.Hour;
      int minute = from.Minute &gt; to.Minute ? to.Minute : from.Minute;
      int second = from.Second &gt; to.Second ? to.Second : from.Second;
      //setting datepicker value
      datepickerFrom.Value = new DateTime(year, month, day, hour, minute, second);
  
  }
  </code></pre>
  
  <p>This works fine, but feels like bit of headache, and I have to do this for <code>datepickerTO_ValueChanged</code> event also, sure I could make one <code>method</code> and call it two times, but still feels like there is a batter way for this, so any suggestions? </p>
  
  <p>Thank you for your time</p>