![](/img/trans.png)
[英]How to set DateTimePicker to certain time and keep the current date?
[英]wpfx:DateTimePicker how to set date and time manually
我有
wpfx:DateTimePicker x:Name =“ dat_reg”
我想现在在窗口上设置日期和时间,我该怎么做。 我的代码是<wpfx:DateTimePicker x:Name="dat_reg" Height="23" Margin="223,270,184,-237" Grid.ColumnSpan="3"></wpfx:DateTimePicker>
public frm_main()
{
InitializeComponent();
//dat_reg.SetValue(DateTime.Now.ToShortDateString());
}
但这行不通。谢谢
而不是设置值,而是使用DateTimePicker
SelectedDate
属性。 您可以使用DateTime
类型存储日期和时间,无需将其转换为string
类型
public frm_main()
{
InitializeComponent();
dat_reg.SelectedDate= DateTime.Now;
//dat_reg.SelectedDate = new DateTime(2018, 05, 07);
//In this way you can assign instance of DateTime with specific Date and time
}
设置Value
属性和FormatString
属性:
dat_reg.Value = DateTime.Now;
dat_reg.Format = Xceed.Wpf.Toolkit.DateTimeFormat.DateTimeFormat.Custom;
dat_reg.FormatString = "d";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.