【发布时间】:2016-07-17 23:56:49
【问题描述】:
我有一个日期时间选择器 dtOtMonth,我只需要显示月份和年份。所以我在表单加载时将其格式化如下。
dtOtMonth.Format = DateTimePickerFormat.Custom;
dtOtMonth.CustomFormat = "MM/yyyy";
但是当我尝试在运行时使用向上/向下箭头编辑日期时,会出现以下错误。
Year、Month 和 Day 参数描述了无法表示的 DateTime。
System.ArgumentOutOfRangeException 未处理 Message="Year、Month 和 Day 参数描述了无法表示的 DateTime。" 来源="mscorlib" 堆栈跟踪: 在 System.DateTime.DateToTicks(Int32 年,Int32 月,Int32 日) 在 System.Windows.Forms.DateTimePicker.SysTimeToDateTime(SYSTEMTIME 秒) 在 System.Windows.Forms.DateTimePicker.WmDateTimeChange(消息& m) 在 System.Windows.Forms.DateTimePicker.WmReflectCommand(消息和 m) 在 System.Windows.Forms.DateTimePicker.WndProc(消息和 m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息和 m) 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg,IntPtr wparam,IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) 在 System.Windows.Forms.Control.SendMessage(Int32 消息,IntPtr wparam,IntPtr lparam) 在 System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, 留言&m) 在 System.Windows.Forms.Control.WmNotify(消息& m) 在 System.Windows.Forms.Control.WndProc(消息和 m) 在 System.Windows.Forms.GroupBox.WndProc(消息和 m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息和 m) 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg,IntPtr wparam,IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) 在 System.Windows.Forms.NativeWindow.DefWndProc(消息和 m) 在 System.Windows.Forms.Control.DefWndProc(消息和 m) 在 System.Windows.Forms.Control.WmKeyChar(消息和 m) 在 System.Windows.Forms.Control.WndProc(消息和 m) 在 System.Windows.Forms.DateTimePicker.WndProc(消息和 m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息和 m) 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg,IntPtr wparam,IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(味精和味精) 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 原因, Int32 pvLoopData) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 原因,ApplicationContext 上下文) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 原因,ApplicationContext 上下文) 在 System.Windows.Forms.Application.Run(窗体 mainForm) 在 E:\HR System\HRProject\Attendence_Module\Attendence_Module\Program.cs:line 中的 Attendence_Module.Program.Main() 17 在 System.AppDomain._nExecuteAssembly(程序集程序集,字符串 [] 参数) 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,String [] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态) 在 System.Threading.ThreadHelper.ThreadStart()
【问题讨论】:
-
我打开了一个 winforms 项目 - 拖了一个
datetimepicker- 在Form_Load事件中复制了您的代码,一切正常。它可以是你的代码中的其他东西吗? -
看下面的stackoverflow.com/a/1608804/1071091可能对你有帮助
-
哇发现了一些东西.. VS-2005???赶紧转2015!!!