DateTimePicker永远不会更新!

Ver*_*cas 13 c# datetimepicker winforms

我有一些DateTimePicker表格永远不会更新.
我试过ValueText,Invalidate()然后Update()Refresh()...

似乎没有什么能改变它们从当前日期开始的价值!
无论我设置什么,当前的日期都是(相对)今天的!

这是.NET 3.5的错误还是什么?
(不,我不能在这个项目中使用.NET 4.)


如果你真的想要一些代码,那么它就是:dateTimePicker1.Value = user.BirthDay;.另外,如果我写的话,MessageBox.Show(user.BirthDay.ToString());我会得到一个很好的方框告诉用户的生日(我的生日,在我的机器上).(所以变量中有一个值...)


我是否还应该提到他们只是为了约会而不是时代?


好的,我知道我需要写更多:

首先,更新控件的方法是订阅Form.Load事件.因此,当窗体和控件可见并且"正在运行"时,它被调用/ fired/invoked.

其次,看看这段代码及其结果:

MessageBox.Show(user.BirthDay.ToString()); // Shows 12.12.1995 (in my regional format)
dateTimePicker1.Value = user.BirthDay; // assigned to 12.12.1995
MessageBox.Show(dateTimePicker1.Value.ToString()); // Shows today's date!
Run Code Online (Sandbox Code Playgroud)

这不好......输出是今天的日期.(到今天我的意思是代码运行的那一天.)

dateTimePicker1.MinDate = new DateTime(1900,1,1); // January 1st, 1900
MessageBox.Show(dateTimePicker1.MinDate.ToString()); // January 1st, 1753 ...
Run Code Online (Sandbox Code Playgroud)

控制不好!1900年不等于1753年!

dateTimePicker1.MaxDate = DateTime.Today;
// In reality, I need it to today's date
MessageBox.Show(dateTimePicker1.MinDate.ToString()); // December 31st, 9998
Run Code Online (Sandbox Code Playgroud)

时间扭曲?O_O

无论如何,整个代码看起来像这样:

public void Form_Load(object sender, EventArgs e)
{
    this.user = User.Load(path);
    // this.user is a field.
    // path is a static field which holds the absolute path of the file in which is serialized that data of the user.

    MessageBox.Show(user.BirthDay.ToString()); // Shows 12.12.1995 (in my regional format)
    dateTimePicker1.Value = user.BirthDay; // assigned to 12.12.1995
    MessageBox.Show(dateTimePicker1.Value.ToString()); // Shows today's date!

    dateTimePicker1.MinDate = new DateTime(1900,1,1); // January 1st, 1900
    MessageBox.Show(dateTimePicker1.MinDate.ToString()); // January 1st, 1753 ...

    dateTimePicker1.MaxDate = DateTime.Today;
    MessageBox.Show(dateTimePicker1.MinDate.ToString()); // December 31st, 9998
}
Run Code Online (Sandbox Code Playgroud)

那么,任何解决方案?XC

小智 22

一个小麻烦有这个麻烦:我的问题是我将DateTimePicker设置为checked = false和(错误地)ShowCheckbox = false; 通过这种设置,我可以设置DTPicker我想要的任何值,但它不会使用自己.