日期时间选择器操作
我有 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 的值设置为比今天提前 1 天。
这段代码给了我一个错误。是的,我知道这是不正确的,但至少我尝试过。有谁愿意帮忙吗?谢谢!
I have 2 dateTimePicker and 1 numericUpDown value.
I want to set my dateTimePicker1 my starting date. and whenever I increase the value of my numericUpdown it increments 1 day from the selected date in dateTimepicker1;
for ex. dateTimePicker1.Value = (feb 18, 2012 -user's choice) dateTimePicker2.Value (feb 18, 2012)
so if the user didn't increment the numericUpDownValue the DTP2 will be equalto DTP1
so if the user increased the numericUpdownValue (for ex 1, the DTP will be (feb 19, 2012));
here's what I've tried:
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);
}
I set the value of the dateTimePicker to 1 Day ahead of the day today.
This Code Gives me an error. Yeah I know it's incorrect but atleast I've tried. Anyone there who is willing to help? THANKS!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经尝试过这样的方法,它对我来说非常有效!
查看下面的代码:
I have tried like this and it works perfect for me !!
Check it out below code: