using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Media;

namespace CountdownTimer
{
    public partial class frm98CountdownTimer : Form
    {
        public frm98CountdownTimer()
        {
            InitializeComponent();
        }

        // Initialize information about the event.
        private const string EventName = "End of the World";
        private DateTime EventDate = DateTime.Now + new TimeSpan(2, 13, 42, 59);

        // Get ready and start the timer.
        private void frm98CountdownTimer_Load(object sender, EventArgs e)
        {
            eventLabel.Text = EventName;
            this.Text = EventName + " at " + EventDate.ToString();
            this.ClientSize = new Size(eventLabel.Bounds.Right, eventLabel.Bounds.Bottom);
            updateTimer.Enabled = true;
        }

        // Update the countdown.
        private void updateTimer_Tick(object sender, EventArgs e)
        {
            TimeSpan remaining = EventDate - DateTime.Now;
            if (remaining.TotalSeconds < 1)
            {
                updateTimer.Enabled = false;
                this.WindowState = FormWindowState.Maximized;
                this.TopMost = true;

                foreach (Control ctl in this.Controls)
                {
                    if (ctl == eventLabel)
                        ctl.Location = new Point(
                            (this.ClientSize.Width - ctl.Width) / 2,
                            (this.ClientSize.Height - ctl.Height) / 2);
                    else ctl.Visible = false;
                }

                using (SoundPlayer player = new SoundPlayer(Properties.Resources.tada))
                {
                    player.Play();
                }
            }
            else
            {
                daysLabel.Text = remaining.Days + " days";
                hoursLabel.Text = remaining.Hours + " hours";
                minutesLabel.Text = remaining.Minutes + " minutes";
                secondsLabel.Text = remaining.Seconds + " seconds";
            }
        }


        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.Label1 = new System.Windows.Forms.Label();
            this.updateTimer = new System.Windows.Forms.Timer(this.components);
            this.eventLabel = new System.Windows.Forms.Label();
            this.hoursLabel = new System.Windows.Forms.Label();
            this.daysLabel = new System.Windows.Forms.Label();
            this.secondsLabel = new System.Windows.Forms.Label();
            this.minutesLabel = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // Label1
            // 
            this.Label1.AutoSize = true;
            this.Label1.ForeColor = System.Drawing.Color.Red;
            this.Label1.Location = new System.Drawing.Point(9, 194);
            this.Label1.Margin = new System.Windows.Forms.Padding(12, 0, 12, 0);
            this.Label1.Name = "Label1";
            this.Label1.Size = new System.Drawing.Size(107, 46);
            this.Label1.TabIndex = 17;
            this.Label1.Text = "Until";
            // 
            // tmrCheckTime
            // 
            this.updateTimer.Interval = 500;
            this.updateTimer.Tick += new System.EventHandler(this.updateTimer_Tick);
            // 
            // eventLabel
            // 
            this.eventLabel.AutoSize = true;
            this.eventLabel.ForeColor = System.Drawing.Color.Red;
            this.eventLabel.Location = new System.Drawing.Point(107, 194);
            this.eventLabel.Margin = new System.Windows.Forms.Padding(12, 0, 12, 0);
            this.eventLabel.Name = "eventLabel";
            this.eventLabel.Size = new System.Drawing.Size(167, 46);
            this.eventLabel.TabIndex = 16;
            this.eventLabel.Text = "<event>";
            // 
            // hoursLabel
            // 
            this.hoursLabel.AutoSize = true;
            this.hoursLabel.ForeColor = System.Drawing.Color.Blue;
            this.hoursLabel.Location = new System.Drawing.Point(9, 55);
            this.hoursLabel.Margin = new System.Windows.Forms.Padding(12, 0, 12, 0);
            this.hoursLabel.Name = "hoursLabel";
            this.hoursLabel.Size = new System.Drawing.Size(183, 46);
            this.hoursLabel.TabIndex = 13;
            this.hoursLabel.Text = "24 hours";
            // 
            // daysLabel
            // 
            this.daysLabel.AutoSize = true;
            this.daysLabel.ForeColor = System.Drawing.Color.Blue;
            this.daysLabel.Location = new System.Drawing.Point(9, 9);
            this.daysLabel.Margin = new System.Windows.Forms.Padding(12, 0, 12, 0);
            this.daysLabel.Name = "daysLabel";
            this.daysLabel.Size = new System.Drawing.Size(165, 46);
            this.daysLabel.TabIndex = 12;
            this.daysLabel.Text = "10 days";
            // 
            // secondsLabel
            // 
            this.secondsLabel.AutoSize = true;
            this.secondsLabel.ForeColor = System.Drawing.Color.Blue;
            this.secondsLabel.Location = new System.Drawing.Point(9, 148);
            this.secondsLabel.Margin = new System.Windows.Forms.Padding(12, 0, 12, 0);
            this.secondsLabel.Name = "secondsLabel";
            this.secondsLabel.Size = new System.Drawing.Size(234, 46);
            this.secondsLabel.TabIndex = 15;
            this.secondsLabel.Text = "59 seconds";
            // 
            // minutesLabel
            // 
            this.minutesLabel.AutoSize = true;
            this.minutesLabel.ForeColor = System.Drawing.Color.Blue;
            this.minutesLabel.Location = new System.Drawing.Point(9, 102);
            this.minutesLabel.Margin = new System.Windows.Forms.Padding(12, 0, 12, 0);
            this.minutesLabel.Name = "minutesLabel";
            this.minutesLabel.Size = new System.Drawing.Size(225, 46);
            this.minutesLabel.TabIndex = 14;
            this.minutesLabel.Text = "59 minutes";
            // 
            // frm98CountdownTimer
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(24F, 46F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(329, 247);
            this.Controls.Add(this.Label1);
            this.Controls.Add(this.eventLabel);
            this.Controls.Add(this.hoursLabel);
            this.Controls.Add(this.daysLabel);
            this.Controls.Add(this.secondsLabel);
            this.Controls.Add(this.minutesLabel);
            this.Font = new System.Drawing.Font("Arial", 30F, System.Drawing.FontStyle.Bold);
            this.Margin = new System.Windows.Forms.Padding(12, 11, 12, 11);
            this.Name = "frm98CountdownTimer";
            this.Text = "CountdownTimer";
            this.Load += new System.EventHandler(this.frm98CountdownTimer_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        internal System.Windows.Forms.Label Label1;
        internal System.Windows.Forms.Timer updateTimer;
        internal System.Windows.Forms.Label eventLabel;
        internal System.Windows.Forms.Label hoursLabel;
        internal System.Windows.Forms.Label daysLabel;
        internal System.Windows.Forms.Label secondsLabel;
        internal System.Windows.Forms.Label minutesLabel;
    }
}