的DateTimePicker永远不会更新! [英] DateTimePicker never updates!

查看:270
本文介绍了的DateTimePicker永远不会更新!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些的DateTimePicker S IN的形式,从来没有更新。结果
我已经试过文本的Invalidate()然后更新()刷新() ...

I have some DateTimePickers in a form that never update.
I've tried Value and Text, Invalidate() and then Update() and also Refresh()...

似乎没有任何从当前日期更改它们的值!结果
不管我怎么设置,当前日期(相对)今天!

Nothing seems to change their values from the current date!
No matter what I set, the current dates are (relatively)today's!

这是一个.NET 3.5的bug还是什么?结果
(不,我不能在这个项目中使用.NET 4)。

Is this a .NET 3.5 bug or what?
(No, I cannot use .NET 4 on this project.)

如果你真的想一些代码,然后在这里它是: dateTimePicker1.Value = user.BirthDay; 。另外,如果我写的 MessageBox.Show(user.BirthDay.ToString()); 我得到一个不错的框,告诉用户的生日(我的生日,我的机器上)。 (所以在变量的值......)

If you really want some code, then here it is: dateTimePicker1.Value = user.BirthDay;. Also, if I write MessageBox.Show(user.BirthDay.ToString()); I get a nice box telling the user's birthday (my birthday, on my machine). (So there is a value in the variable...)

我应该还提到,他们只是日期和?没有时间

Should I also mention that they are only for dates and not times?

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

Ok, I see I need to write more:

首先,在控制更新的方法订阅 Form.Load 事件。因此,它被称为/烧制/时的形式和控制是可见和跑调用。

First of all, the method in which the control is updated is subscribed to the Form.Load event. Consequently, it is called/fired/invoked when the form and the controls are visible and "running".

其次,看该段代码,并且结果:

Secondly, look at this pieces of code and their result:

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!

这不是很好......输出为今天的日期。 (按今天我的意思是该代码运行的日子。)

That's not nice... The output is today's date. (By today I mean the day in which the code was ran.)

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



控制不好! !1900不等于1753

Bad control! 1900 doesn't equal to 1753!

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



时间隧道? O_O

Time warp? O_O

总之,整个代码看起来是这样的:

Anyway, the whole code looks like this:

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
}



因此,任何解决办法吗? XC

So, any solution? xC

推荐答案

一个小小的暗示这个烦恼:我的问题是,我有的DateTimePicker设置检查=假,(错)ShowCheckbox = FALSE;
有了这个设置,我可以设置为DTPicker我想任何值,但不会uDate公司本身。

One small hint with this trouble: my problem was that I had the DateTimePicker set to checked=false and (by mistake) ShowCheckbox=false; With this setup I could set to DTPicker whatever value I wanted, but it won't udate itself.

这篇关于的DateTimePicker永远不会更新!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆