Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I want to make ana alarm and I wrote some code about it. But I can't add a music.
Please help me.
C#
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;
using System.Globalization;
using System.Diagnostics;

namespace ALARM
{
    public partial class Alarm : Form
    {
        public Alarm()
        {
            InitializeComponent();
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            bool isAlarmOk = true;

            while (isAlarmOk)
            {
                string dt = DateTime.Now.ToShortTimeString();
                
                if (string.Compare(dt,txtTime.Text) == 0)
                {
                    isAlarmOk = false;
                    SoundPlayer sp = new SoundPlayer();
                    sp.SoundLocation = @"C:\Users\Rahsan-PC\Documents\Visual Studio 2012\Projects\ALARM\ALARM\bin\Debug\sound\ding.wav";
                    sp.Load();
                    sp.PlaySync();
                    break;
                }
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            timer1.Stop();
        }

        private void Alarm_Load(object sender, EventArgs e)
        {
            txtDay.Text = DateTime.Now.ToShortDateString();
            txtTime.Text = DateTime.Now.ToShortTimeString();
        }
    }
}
Posted
Updated 15-Sep-14 22:06pm
v2
Comments
goksurahsan 16-Sep-14 3:56am    
There is a wrong , but I didn't understand.
George Jonsson 16-Sep-14 4:11am    
Do you get any error message?
goksurahsan 16-Sep-14 4:17am    
I didn't get any error but it didn't work .
BillWoodruff 16-Sep-14 4:15am    
Your code shows you use a Timer, but the only code for the Timer visible is where you stop it in the btnClose Click EventHandler.

So, where is the Timer started, and how do you use it ?

1 solution

Hi,

Use a timer to create a simple alarm application[^]

This article may very helpful for you
 
Share this answer
 
Comments
goksurahsan 16-Sep-14 5:24am    
okey thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900