C# 日期时间选择器操作

C# 日期时间选择器操作,c#,datetime,datepicker,datetimepicker,numericupdown,C#,Datetime,Datepicker,Datetimepicker,Numericupdown,我有2个dateTimePicker和1个numericUpDown值 我想将dateTimePicker1设置为我的开始日期。每当我增加numericUpdown的值时,它会从dateTimepicker1中选择的日期开始增加1天 例如dateTimePicker1.Value=(2012年2月18日-用户选择)dateTimePicker2.Value(2012年2月18日) 因此,如果用户没有增加numericUpDownValue,DTP2将等于DTP1 因此,如果用户增加numeric

我有2个dateTimePicker和1个numericUpDown值

我想将dateTimePicker1设置为我的开始日期。每当我增加numericUpdown的值时,它会从dateTimepicker1中选择的日期开始增加1天

例如dateTimePicker1.Value=(2012年2月18日-用户选择)dateTimePicker2.Value(2012年2月18日)

因此,如果用户没有增加numericUpDownValue,DTP2将等于DTP1

因此,如果用户增加numericUpdownValue(对于ex 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的值设置为今天的前一天


这个代码给了我一个错误。是的,我知道这不正确,但至少我试过了。有谁愿意帮忙吗?谢谢

我试过这样做,它对我来说非常适合!!

查看下面的代码:


“这个代码给了我一个错误。”--什么错误?编译器错误还是运行时错误?消息说什么?逻辑错误?datetimepicker2不是从datetimepicker1开始的,我不知道如何在dtpsir上添加一天。您的代码中有一个错误。(例如:numericUpDown.value=1)它增加(1+1+1…)天。但是,如果我再次单击NumericUpdown(值=2),它会增加两天!所以我加的总天数是3天(必须是2天)。它不加1。它增加了(1+2+3…),因此,如果我在数字上下菜单中单击3次,它会增加(6天,必须只有3天)。此外,每当我减小numericupdown的值时,它不会减法。除息的
    private void numericUpDown1_ValueChanged(object sender, EventArgs e)
    {
        dateTimePicker2.Value = dateTimePicker2.Value.AddDays(Convert.ToInt32(numericUpDown1.Value));

    }