简体   繁体   中英

C# numericUpDown time validate

Is it possible to make this code simpler?

private void hourNumericUpDown_ValueChanged(object sender, EventArgs e)
{
    if (hourNumericUpDown.Value == 0 & minutesNumericUpDown.Value == 0) { okButton.Enabled = false; } else okButton.Enabled = true;
    // same in minutesNumericUpDown's event
}

Update 1: button3 should actually be okButton too in OP's question. Update 2: this is a timer

I am assuming that you want:

  • OK button enabled when Hours > 0 or Minutes > 0

Try:

okButton.Enabled = hourNumericUpDown.Value > 0 || minutesNumericUpDown.Value > 0;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM