the bug of datetimepicker control?
-
Environment: vs2003.net winform,windows application Form1: components: - datetimePicker1 - button1 - toolbar1 - toolbarButton1 events: button1_onclick(object sender,EventAgs e) { MessageBox.Show(datetimePicker1.Value.ToString("yyyy-MM-dd")); } toolbar_onclick(...) { if(e.Button == toolbarButton1) MessageBox.Show(datetimePicker1.Value.ToString("yyyy-MM-dd")); } test: suppose the original value of the datetimepicker is:2006-10-12 and now enter a number 11 into the month-part of the datetimepicker,then click button1,a messagebox shows:2006-11-12,not 2006-10-12. and follow the step,enter another number:9 into the month-part of the datetimepicker,and click toolbarButton1,a messagebox shows a value also,however it's not 2006-09-12(normally it should be this),it's 2006-11-12. for this,I conclude that datetimepicker's value is not synchronous with the mannual input from keyboard,after it's not out of focus,then value will be updated.after input,for button1,when I click it,it will occur that datetimepicker will be out of focus,however toolbarbutton1 not.so this is the difference between button and toolbarbutton,and the difference leads to a wrong value when getting datetimepicker's value in both events. and who can tell me how to resove the problem? much thanx~
-
Environment: vs2003.net winform,windows application Form1: components: - datetimePicker1 - button1 - toolbar1 - toolbarButton1 events: button1_onclick(object sender,EventAgs e) { MessageBox.Show(datetimePicker1.Value.ToString("yyyy-MM-dd")); } toolbar_onclick(...) { if(e.Button == toolbarButton1) MessageBox.Show(datetimePicker1.Value.ToString("yyyy-MM-dd")); } test: suppose the original value of the datetimepicker is:2006-10-12 and now enter a number 11 into the month-part of the datetimepicker,then click button1,a messagebox shows:2006-11-12,not 2006-10-12. and follow the step,enter another number:9 into the month-part of the datetimepicker,and click toolbarButton1,a messagebox shows a value also,however it's not 2006-09-12(normally it should be this),it's 2006-11-12. for this,I conclude that datetimepicker's value is not synchronous with the mannual input from keyboard,after it's not out of focus,then value will be updated.after input,for button1,when I click it,it will occur that datetimepicker will be out of focus,however toolbarbutton1 not.so this is the difference between button and toolbarbutton,and the difference leads to a wrong value when getting datetimepicker's value in both events. and who can tell me how to resove the problem? much thanx~
Maybe the following helps you out. At least it gets rid of duplicate code.
toolbar_onclick(...)
{
if(e.Button == toolbarButton1)
button1.PerformClick();
}
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
Maybe the following helps you out. At least it gets rid of duplicate code.
toolbar_onclick(...)
{
if(e.Button == toolbarButton1)
button1.PerformClick();
}
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
adding some buttons can resove the problem,but it seems awkward and duplicate. thank you very much anyway.