【发布时间】:2012-02-18 08:26:00
【问题描述】:
我有 2 个 dateTimePicker 和 1 个 numericUpDown 值。
我想将 dateTimePicker1 设置为我的开始日期。并且每当我增加 numericUpdown 的值时,它都会从 dateTimepicker1 中的选定日期增加 1 天;
例如。 dateTimePicker1.Value =(2012 年 2 月 18 日 - 用户选择) dateTimePicker2.Value(2012 年 2 月 18 日)
所以如果用户没有增加 numericUpDownValue,DTP2 将等于 DTP1
因此,如果用户增加 numericUpdownValue(例如 1,则 DTP 将为(2012 年 2 月 19 日));
这是我尝试过的:
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
this.dateTimePicker1.MinDate = DateTime.Today.AddDays(1);
this.dateTimePicker2.Value = dateTimePicker1.Value;
}
private void numericUpDown1_ValueChanged_1(object sender, EventArgs e)
{
int counter = Convert.ToInt16(numericUpDown1.Value + 1);
this.dateTimePicker2.Value = DateTime.Now.AddDays(counter);
}
我将 dateTimePicker 的值设置为今天提前 1 天。
此代码给我一个错误。是的,我知道这是不正确的,但至少我已经尝试过了。有愿意帮忙的吗?谢谢!
【问题讨论】:
-
"此代码给我一个错误。" ——什么错误?编译器错误或运行时错误?消息说了什么?
-
逻辑错误? datetimepicker2 不是从 datetimepicker1 的日期开始的,我不知道如何在 dtp 上添加一天
标签: c# datetime datepicker datetimepicker numericupdown