c**t 发帖数: 2744 | 1 There are two dateTimePickers on a winform, which requires dt2 > dt1;
if dt1 is picked greater than dt2, reset dt1 to dt2-1; but the messagebox
pops
out twice. How to disable the second one? ..EnableEvents seems not working
//The code is as follows.
private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
{
if (this.dateTimePicker1.Value > this.dateTimePicker2.Value)
{
MessageBox.Show("This date should NOT be earlier then " +
this.dateTimeP |
k****i 发帖数: 1072 | 2 Per your description, the code should be changed as follows:
private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
{
if (this.dateTimePicker1.Value > this.dateTimePicker2.Value)
{
MessageBox.Show("This date should NOT be earlier then " +
this.dateTimePicker1.Value.ToShortDateString() + "!");
this.Application.EnableEvents = false;
this.dateTimePicker1.Value = this.dateTimePicker2.Value.
AddDays(-1);
【在 c**t 的大作中提到】 : There are two dateTimePickers on a winform, which requires dt2 > dt1; : if dt1 is picked greater than dt2, reset dt1 to dt2-1; but the messagebox : pops : out twice. How to disable the second one? ..EnableEvents seems not working : //The code is as follows. : private void dateTimePicker2_ValueChanged(object sender, EventArgs e) : { : if (this.dateTimePicker1.Value > this.dateTimePicker2.Value) : { : MessageBox.Show("This date should NOT be earlier then " +
|
c**t 发帖数: 2744 | 3 the messagebox is still called twice.
I tried both:
this.Application.EnableEvents = false;
this.dateTimePicker1.Value = this.dataTimePicker2.Value.AddDays(-1);
this.Application.EnableEvents = true;
and
Globals.ThisWorkbook.Application.EnableEvents = false;
..
Globals.ThisWorkbook.Applicaiton.EnableEvents = true;
Neither worked.
【在 k****i 的大作中提到】 : Per your description, the code should be changed as follows: : private void dateTimePicker2_ValueChanged(object sender, EventArgs e) : { : if (this.dateTimePicker1.Value > this.dateTimePicker2.Value) : { : MessageBox.Show("This date should NOT be earlier then " + : this.dateTimePicker1.Value.ToShortDateString() + "!"); : this.Application.EnableEvents = false; : this.dateTimePicker1.Value = this.dateTimePicker2.Value. : AddDays(-1);
|
c**t 发帖数: 2744 | 4 I used a static counter, and confirmed that the popup was called twice
【在 k****i 的大作中提到】 : Per your description, the code should be changed as follows: : private void dateTimePicker2_ValueChanged(object sender, EventArgs e) : { : if (this.dateTimePicker1.Value > this.dateTimePicker2.Value) : { : MessageBox.Show("This date should NOT be earlier then " + : this.dateTimePicker1.Value.ToShortDateString() + "!"); : this.Application.EnableEvents = false; : this.dateTimePicker1.Value = this.dateTimePicker2.Value. : AddDays(-1);
|
k****i 发帖数: 1072 | 5 Does the dateTimePicker1.Value change between these two calls?
【在 c**t 的大作中提到】 : I used a static counter, and confirmed that the popup was called twice
|
c**t 发帖数: 2744 | 6 obviously!
【在 k****i 的大作中提到】 : Does the dateTimePicker1.Value change between these two calls?
|
c**t 发帖数: 2744 | 7 found solution!
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
this.dateTimePicker1.MaxDate = this.dateTimePicker2.Value;
..
}
private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
{
this.dateTimePicker2.MinDate = this.dateTimePicker1.Value;
..
}
working
【在 c**t 的大作中提到】 : There are two dateTimePickers on a winform, which requires dt2 > dt1; : if dt1 is picked greater than dt2, reset dt1 to dt2-1; but the messagebox : pops : out twice. How to disable the second one? ..EnableEvents seems not working : //The code is as follows. : private void dateTimePicker2_ValueChanged(object sender, EventArgs e) : { : if (this.dateTimePicker1.Value > this.dateTimePicker2.Value) : { : MessageBox.Show("This date should NOT be earlier then " +
|