[英]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.