在 c# 中插入多日期警报

问题描述 投票:0回答:1

我想做多日期闹钟,但我不知道可以让它成为可能的代码

  private void timer1_Tick(object sender, EventArgs e)
        {
            DateTime currentTime = DateTime.Now;
            DateTime alarmTime = dateTimePicker1.Value;
           


            if (currentTime.Hour==alarmTime.Hour && currentTime.Minute==alarmTime.Minute && currentTime.Second == alarmTime.Second)

            {
                timer1.Stop();
                pictureBox1.Visible = true;

in DateTime alarmTime = dateTimePicker1.Value; 我想放置超过 1 个值,即 dateTimePicker1 和 dateTimePicker2 以及 dateTimePicker3 和 dateTimePicker4 以及 dateTimePicker5 有什么办法可以做到这一点?谢谢

我试过这个

 DateTime alarmTime = dateTimePicker1.Value;
 DateTime alarmTime = dateTimePicker2.Value;
 DateTime alarmTime = dateTimePicker3.Value;
 DateTime alarmTime = dateTimePicker4.Value;
 DateTime alarmTime = dateTimePicker5.Value;

但是没用

“这个范围内已经定义了名为‘alarmTime’的函数”

c# windows-forms-designer
1个回答
0
投票

不能用相同的名称定义相同的对象,在这种情况下

alarmTime

做这样的事情:

 DateTime alarmTime1 = dateTimePicker1.Value;
 DateTime alarmTime2 = dateTimePicker2.Value;
 DateTime alarmTime3 = dateTimePicker3.Value;
 DateTime alarmTime4 = dateTimePicker4.Value;
 DateTime alarmTime5 = dateTimePicker5.Value;

或者按照 jmcilhinney 的建议,使用

array
List

List<DateTime> alarmTime = new List<DateTime>();
alarmTime.Add(dateTimePicker1.Value);
alarmTime.Add(dateTimePicker2.Value);
alarmTime.Add(dateTimePicker3.Value);
alarmTime.Add(dateTimePicker4.Value);
alarmTime.Add(dateTimePicker5.Value);
© www.soinside.com 2019 - 2024. All rights reserved.