The alarm clock application works by setting a certain time and then it perform a certain task eg:sound an alarm, display a messagebox test message. But the problem comes where i need to snooze(delay) the alarm clock for a certain time period like 10 second... Then it will re-initialise the initial alarm clock function.
i tried this but it doesn't work... Why? or is there other methods to snooze the alarm clock?

    DateTime SnoozeTime; // global
    private void btnSNOOZE_Click(object sender, EventArgs e)
    {
        pnlDisplay.BackColor = SystemColors.Control;
        myPlayer.Stop();
        SnoozeTime = DateTime.Now.AddSeconds(10);
        Time2.Enabled = true;
    }

    private void Time2_Tick_1(object sender, EventArgs e)
    {
        if (DateTime.Now == SnoozeTime)
        {
            Time.Enabled = false;

            Random Random = new Random();
            Color[] strColor = { Color.Red, Color.Blue, Color.Green, Color.Yellow };
            pnlDisplay.BackColor = strColor[Random.Next(0, strColor.Length)];

            myPlayer.SoundLocation = @"C:\Users\Tan Woon Pang\Desktop\Alarm Clock\Alarm Clock\bin\B.wav";
            myPlayer.PlayLooping();

            MessageBox.Show(txtReminder.Text, "Reminder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            btnResetTime.Enabled = true;
            btnSNOOZE.Enabled = true;
        }
    } 

Recommended Answers

All 7 Replies

try using timer.Start() and timer.Stop() rather than changing timer.Enabled.

I see that the timer event is "Time2_Tick_1" with a 1 at the end. This usually occurs when an event handler is created again for the same object.
Is Time2_Tick_1 used for the original alarm time event?

Note: Using if (DateTime.Now == value) might not trigger as the times are unlikely to ever be exactly the same.
Use if (DateTime.Now >= value) instead.

Thanks for above guidance now the problem has party been solved. :)
But may i know why that my class system does not help to check the time value entered beause you can't be entering 99:99 into a 24hour clock time and expect it to run?

private string m_strTime = "";
        private Time m_objTime;

        private void InputTime()
        {
            int intHour;
            int intMinute;

            string strDisplay;

            if (m_strTime.Length > 4)
            {
                m_strTime = m_strTime.Substring(0, 4);
            }

            strDisplay = m_strTime.PadLeft(4, Convert.ToChar("0"));

            intHour = Int32.Parse(strDisplay.Substring(0, 2));
            intMinute = Int32.Parse(strDisplay.Substring(2, 2));

            m_objTime = new Time(intHour, intMinute);
            
            lblAlarmDisplay.Text = String.Format("{0:D2}:{1:D2}", intHour, intMinute);
        }

        private void btnSetTime_Click(object sender, EventArgs e)
        {
            txtReminder.Enabled = false;
            pnlKeyBoard.Enabled = false;
            btnResetTime.Enabled = true;
            Time.Enabled = true;
        }

        private void Time_Tick(object sender, EventArgs e)
        {
            if (string.Format("{0:D2}:{1:D2}", m_objTime.Hour, m_objTime.Minute) == string.Format("{0:HH:mm}", DateTime.Now))
            {
                Time.Enabled = false;

                Random Random = new Random();
                Color[] strColor = { Color.Red, Color.Blue, Color.Green, Color.Yellow };
                pnlDisplay.BackColor = strColor[Random.Next(0, strColor.Length)];

                myPlayer.SoundLocation = @"C:\Users\Tan Woon Pang\Desktop\Alarm Clock\Alarm Clock\bin\B.wav";
                myPlayer.PlayLooping();

                MessageBox.Show(txtReminder.Text, "Reminder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                btnSNOOZE.Enabled = true;
            }
        }

        DateTime SnoozeTime;

        private void btnSNOOZE_Click(object sender, EventArgs e)
        {
            btnResetTime.Enabled = false;
            pnlDisplay.BackColor = SystemColors.Control;
            myPlayer.Stop();
            SnoozeTime = DateTime.Now.AddSeconds(10);
            TimerCheck.Enabled = true;
        }

        private void TimerCheck_Tick(object sender, EventArgs e)
        {
            if (DateTime.Now >= SnoozeTime)
            {
                TimerCheck.Enabled = false;

                Random Random = new Random();
                Color[] strColor = { Color.Red, Color.Blue, Color.Green, Color.Yellow };
                pnlDisplay.BackColor = strColor[Random.Next(0, strColor.Length)];

                myPlayer.SoundLocation = @"C:\Users\Tan Woon Pang\Desktop\Alarm Clock\Alarm Clock\bin\B.wav";
                myPlayer.PlayLooping();

                MessageBox.Show(txtReminder.Text, "Reminder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                btnResetTime.Enabled = true;
                btnSNOOZE.Enabled = true;
            }
        }
        
        private void btnResetTime_Click(object sender, EventArgs e)
        {
            btnSNOOZE.Enabled = false;
            pnlKeyBoard.Enabled = true;
            txtReminder.Text = "";
            txtReminder.Enabled = true;
            lblAlarmDisplay.Text = "00:00";
            pnlDisplay.BackColor = SystemColors.Control;
            myPlayer.Stop();
            m_strTime = "";
            m_objTime = new Time(0, 0);
        }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Alarm_Clock
{
    public class Time
    {
        private int m_intHour;
        private int m_intMinute;

        public Time(int hourValue, int minuteValue)
        {
            Hour = hourValue;
            Minute = minuteValue;
        }

        public int Hour
        {
            get
            {
                return m_intHour;
            }
            set
            {
                if (value < 24)
                {
                    m_intHour = value;
                }
                else
                {
                    m_intHour = 0;
                }
            }
        }

        public int Minute
        {
            get
            {
                return m_intMinute;
            }
            set
            {
                if (value < 60)
                {
                    m_intMinute = value;
                }
                else
                {
                    m_intMinute = 0;
                }
            }
        }
    }
}

Sir I have 100 customer in my application , i have customer id (GUID) each my customer , but now i want set my snooze time diffrent for each of my Customer, how can i do this , if anyone have code then please help me and send me code , thanks in advance

first of all you should make a new thread. I do know how your data is stored but neverless, you should specify for each one of them the snooze time and then do your code logic...

hi imso can you please provide me the full score of your clock with designer pllzzz ajay.kadian99@gmail.com this is my mail id.

Can you share full code ? i need it now i have a task about C# alarm application

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.