简体   繁体   English

DateTimePicker C#在Windows XP上无法正常工作

[英]DateTimePicker C# not working correctly on Windows XP

I am creating a WinForms app that uses the DateTimePicker control, my dev machine is a Windows 7 machine, the control works fine, no problems or issues. 我正在创建一个使用DateTimePicker控件的WinForms应用程序,我的开发机是Windows 7计算机,该控件工作正常,没有问题。 But when I deploy this WinForm to an XP machine, and try to use the DateTimePicker control it opens up the calendar, but upon selection of a date the calendar does not go away as it does on my dev machine. 但是,当我将此WinForm部署到XP计算机上并尝试使用DateTimePicker控件时,它将打开日历,但是选择日期后,日历不会像在我的开发计算机上那样消失。

Please advise on how to rectify this. 请提供有关纠正方法的建议。

Thanks in advance. 提前致谢。

This is all I am doing when selecting a value from the DateTimePicker control: 当从DateTimePicker控件中选择一个值时,这就是我要做的一切:

private void dateTimePickerStartDate_ValueChanged(object sender, EventArgs e)
        {
            dateTimePickerStartDate.Format = DateTimePickerFormat.Long;
        }

        private void dateTimePickerEndDate_ValueChanged(object sender, EventArgs e)
        {
            dateTimePickerEndDate.Format = DateTimePickerFormat.Long;
        }

I finally solved this! 我终于解决了! For some reason XP does not seam to like this line of code: 由于某些原因,XP不会喜欢下面这行代码:

dateTimePickerStartDate.Format = DateTimePickerFormat.Long;
dateTimePickerEndDate.Format = DateTimePickerFormat.Long;

So if you set your datetimepicker's format to long XP does not close the calendar on selection of a date. 因此,如果将datetimepicker的格式设置为long XP,则在选择日期时不会关闭日历。

To solve this set you datetimepicker's format to this (if you want to use the long format) : 要解决此设置,您需要将datetimepicker的格式设置为此(如果要使用长格式):

dateTimePickerStartDate.Format = DateTimePickerFormat.Custom;    
dateTimePickerStartDate.CustomFormat = "dd MMMM yyyy";

dateTimePickerEndDate.Format = DateTimePickerFormat.Custom;    
dateTimePickerEndDate.CustomFormat = "dd MMMM yyyy";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM