[RESOLVED] [2.0] DateTimePicker Increments
Hey guys. I am using a DateTimePicker on my form with the ShowUpDown property set to true. Would it be
possible to make it so when you click up on the minutes side, it goes up by 15? Like.. Here's an example
The DateTimePicker says this:
05:00
The 05 is the hours and the 00 is the minutes
Anyways, you have the 00 selected and you click up once and then it goes right up to 05:15, then 05:30, etc...
etc.. Thanks for any help
Re: [2.0] DateTimePicker Increments
It wouldn't really make sense to do that because while you may want the minutes to increment by 15 at a time, would you want the hours to do the same? If you want to force the time to always be at a quarter hour you could handle the ValueChanged event and then round the time to a quarter hour. It would be tricky though because if you simply round the time then you'll never be able to change it using the arrows because it will always round back to the same time. You would have to keep the previous time in a variable and in the event handler compare the new time to that to know whether to round up or down. Then you'll also have to take into account when the user types in a new time so the difference will not be just one minute.
Re: [2.0] DateTimePicker Increments
Nevermind, Conipto helped me. It all works now :)
Oh, and so iPrank isn't raggin' on me again.. here :P
Code:
private DateTime[] last = new DateTime[12];
private void dateTimePickers(object sender)
{
DateTimePicker DT = (DateTimePicker)sender;
int min = 0;
if ((DT.Value.Minute == 0) | (DT.Value.Minute == 15) | (DT.Value.Minute == 30) | (DT.Value.Minute == 45)) return;
if (DT.Value.Minute > last[Convert.ToInt32(DT.Tag)].Minute)
{
switch (DT.Value.Minute)
{
case 1: min = 15; break;
case 16: min = 30; break;
case 31: min = 45; break;
case 59: min = 45; break;
}
}
else
{
switch (DT.Value.Minute)
{
case 44: min = 30; break;
case 29: min = 15; break;
case 14: min = 0; break;
}
}
DT.Value = new DateTime(DT.Value.Year, DT.Value.Month, DT.Value.Day, DT.Value.Hour, min, 0);
last[0] = firststartbox.Value;
last[1] = firstendbox.Value;
last[2] = secondstartbox.Value;
last[3] = secondendbox.Value;
last[4] = thirdstartbox.Value;
last[5] = thirdendbox.Value;
last[6] = fourthstartbox.Value;
last[7] = fourthendbox.Value;
last[8] = fifthstartbox.Value;
last[9] = fifthendbox.Value;
last[10] = sixthstartbox.Value;
last[11] = sixthendbox.Value;
}
And to call it from a ValueChanged event handler
Code:
dateTimePickers(((DateTimePicker)sender));
Normally, I would just use EventArgs and stuff and just use it globally from the events tab in the properties window but I am performing other statements in the valuechanged event handler, so it wouldn't make sense to do that
Re: [2.0] DateTimePicker Increments
Quote:
Originally Posted by Fromethius
Oh, and so iPrank isn't raggin' on me again.. here :P
Use the small case :p. http://www.vbforums.com/images/smilies/tongue.gif
Sorry, couldn't resist. http://www.vbforums.com/images/smilies/biggrin.gif