我有 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 天。
此代码给了我一个错误。是的,我知道这是不正确的,但至少我已经尝试过了。有愿意帮忙的吗?谢谢!