事实:
为什么会这样?我怎么能避免呢?
我正在使用这个漂亮的小日期和时间选择器[ http://trentrichardson.com/examples/timepicker/ ].如何设置选择器打开的日期和时间?
我有一个DateTimePicker,我设置为只显示月份和年份,如下所示:
myDateTimePicker.Format = DateTimePickerFormat.Custom;
myDateTimePicker.CustomFormat = "MMMM yyyy";
myDateTimePicker.ShowUpDown = true;
Run Code Online (Sandbox Code Playgroud)
不过,我想日期的价值永远是所选月份的最后一天,所以我设置使用ValueChanged事件的日期时间:
DateTime selectedDate = myDateTimePicker.Value;
DateTime lastDayOfMonth = new DateTime(
selectedDate.Year,
selectedDate.Month,
DateTime.DaysInMonth(selectedDate.Year, selectedDate.Month));
myDateTimePicker.Value = lastDayOfMonth;
Run Code Online (Sandbox Code Playgroud)
问题是,如果我选择了像March这样的月份,并且使用向上/向下控件将月份更改为2月,则在处理ValueChanged事件之前会出现以下错误:
ArgumentOutOfRangeException was unhandled
Year, Month, and Day parameters describe an un-representable DateTime.
Run Code Online (Sandbox Code Playgroud)
这是可以理解的,因为日期是3月31日,并且它被更改为2月31日,这是无效日期.但是,我想将其更改为2月28日(或2月29日).
我怎样才能做到这一点?
我有一个用户控件,其中DateTimePicker覆盖了
覆盖DateTimePicker的文本部分的单行文本框(Tb).文本框Tb(绿色)被锚定(LTRB).

调整usercontrol的大小时会出现问题.
重叠的datetimepicker显示在文本Tb后面.

目前,用户控制是242(W)×20(H).当控件调整到100(宽度)以下时出现问题.
我尝试将CustomFormat设置为""的文本留空,但用户控件支持许多datetimepicker功能,因此这不是一个选项.
我试图在用户控件上设置最小大小,但这也不起作用.
编辑:
该控件已在少数应用程序中使用.在这些应用程序中,控件的最小大小为90X20,而我们现在设置的最小大小为97x20.
VS设计师在进行更改后会将现有控件的大小调整为97x20吗?
如何实现这种效果(重新调整为97x20)?
添加最小尺寸后编辑****代码****
namespace WindowsFormsApplication1
{
partial class CDatePicker
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
private void InitializeComponent()
{
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.datepanel = new System.Windows.Forms.Panel();
this.datetxt = new System.Windows.Forms.TextBox();
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
this.timepanel = new System.Windows.Forms.Panel();
this.timetxt = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout(); …Run Code Online (Sandbox Code Playgroud) 我已经看到了一些选择日期范围的jQuery滑块的好例子:http://ghusse.github.com/jQRangeSlider/stable/demo/
时间范围:http://marcneuwirth.com/blog/2011/05/22/revisiting-the-jquery-ui-time-slider/
但我正在寻找能够选择日期,月,日分钟的东西.能够将它作为日期范围选择器和普通滑块都很棒.
有没有人见过这样的实现?使用Unix时间作为我的值的正常jQuery UI滑块是否有意义?
我试图将当前时间设置为DateTimePicker(使用格式时间)
this.myDateTimePicker.Value = DateTime.Now;
Run Code Online (Sandbox Code Playgroud)
但在执行我的代码时,我得到一个例外
Object reference not set to an instance of an object
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
谢谢.
我正在尝试使用新的dateTimePicker for Windows 8.1:
<DatePicker HorizontalAlignment="Left" Margin="401,245,0,0" Grid.Row="1"
VerticalAlignment="Top" Width="352" Date="{Binding personSingle.personDOB,Mode=TwoWay}"/>
Run Code Online (Sandbox Code Playgroud)
当我改变日期时,当我查看personDOB的值时,我没有得到我选择的值.personDOB的类型为DateTimeOffset
我需要做什么才能获得我选择的价值?
更新:
<DatePicker x:Name="dtPick" HorizontalAlignment="Left" Margin="401,245,0,0" Grid.Row="1"
VerticalAlignment="Top" Width="352" DataContext="{Binding personSingle}"
Date="{Binding personSingle.personDOB.Date,Mode=TwoWay}"/>
Run Code Online (Sandbox Code Playgroud) 我正在使用这个datetimepicker jQuery插件:http : //xdsoft.net/jqplugins/datetimepicker/,但我不知道如何使用时区。我看到了文档,但是找不到。
我试图做的是这样的:
serviceDateTime.datetimepicker({
lang: 'pt-BR',
format: 'd/m/Y H:i',
mask: true,
step: 30,
showTimezone: true,
timezone: "-0200"
});
Run Code Online (Sandbox Code Playgroud)
有什么帮助吗?提前致谢!
我正在建立一个家谱树应用程序,我需要达到这个日期.我更喜欢DateTimePicker而不是TextBox + text-date转换.
反正有没有规避这个限制?
我想从DateTimePickerVB中选择值(如果我只选择日值,那么我只想获得选定的日值.)
在这张图片中,我从中选择了(蓝色标记)年份值DateTimePicker.所以我只需要今年的价值.
在TextBox我可以获得选定值的情况下
TextEndTime.SelectedText
Run Code Online (Sandbox Code Playgroud)
是否有任何语法或方法可以从中获取选定的值DateTimePicker?
datetimepicker ×10
c# ×5
winforms ×4
jquery ×3
.net ×1
exception ×1
jquery-ui ×1
timezone ×1
uislider ×1
vb.net ×1
windows-8 ×1
windows-8.1 ×1
winrt-xaml ×1