当设置 MaxDate 时,DateTimePicker 在 XP 和 Windows Server 2008 中的行为有所不同?
我在我的 winform 应用程序中使用 DateTimePicker 。 DateTimePicker 允许用户选择不大于 DateTime.Now 的日期。我通过将控件 MaxDate 设置为 DateTime.Now 来做到这一点。
它在 XP 中工作正常,显示大于 DateTime.Now 的日期,并且用户无法选择它们。但在 Windows Server 2008 中,这些日期根本不显示。
这是预期行为还是微软错误?
XP Windows Server 2008
I'm using DateTimePicker in my winform application. The DateTimePicker allows a user to select a date that is not larger than DateTime.Now. I did this by set the controls MaxDate to DateTime.Now.
It works fine in XP, the dates that are larger than DateTime.Now are displayed, and user can not select them. But in Windows Server 2008, these dates are not displayed at all.
Is this an expected behavior or a microsoft bug?
XP
Windows Server 2008
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
本机 Windows 月历控件在 Vista 中进行了相当大的修改,这也是 Windows 2008 的底层代码库。这影响了 DateTimePicker 和 MonthCalendar 类,它们是围绕本机 Windows 提供的代码的非常简单的 .NET 包装器。很多Winforms 类都是这样的。
这在其他方面被认为是一件好事,您的 UI 会自动适应新操作系统的外观和感觉以及其他程序在该系统上的行为方式,而无需您执行任何操作。不显示您设置为不可选择的日期可以说是非常有意义的。否则,您无法做任何事情来改变本机 Windows 代码的行为方式,这些包装器非常薄。主要是因为本机 Windows 控件没有很多旋钮。
功能,而不是错误。
The native Windows month calendar control got a pretty major overhaul at Vista, also the underlying code base for Windows 2008. That affected the DateTimePicker and MonthCalendar classes, they are pretty simple .NET wrappers around the native Windows provided code. Lots of Winforms classes are like this.
This is otherwise considered a nicety, your UI automagically adapts itself to the look-and-feel of the new operating system and the way other programs behave on it without you having to do anything at all. Not displaying dates that you've made unselectable does arguably make an enormous amount of sense. There is otherwise not anything you can do to change the way that native Windows code behaves, those wrappers are very thin. Mostly because the native Windows controls don't have a lot of knobs.
Feature, not a bug.
许多 .NET 控件都依赖于底层操作系统。如果 Windows 用于表示日期时间选择器的底层控件不同,那么在 Winforms 应用程序中显示的控件也会不同。
您可以看到,仅在 XP 上,控件就很容易受到操作系统的影响。将您的主题从默认的标准“卡通”主题更改为 Windows 经典并运行您的 .NET 应用程序。表单边框将从圆角和卡通界面变为经典格式。
Windows 默认使用的日期时间选择器位于 MScomctl.ocx 中。
如果 Windows 版本之间的情况发生了变化(我确信确实如此),那么您的 windows 的外观和/或行为将相应地有所不同。
Many of the .NET controls depend on the underlying operating system. If the underlying control that Windows uses to represent a date-time chooser is different, then the one that shows up in your Winforms application will be different.
You can see that the controls are influenced by the operating system easily enough just on XP. Change your theme from the standard "cartoony" theme that is the default to Windows Classic and run your .NET apps. The form borders will go from haing the rounded corners and cartoony interface to having the classic format.
The date-time chooser that Windows uses by default is in the MScomctl.ocx.
If this changed between versions of Windows (which I'm sure it did) then your windorms will look and/or behave differently accordingly.