Click here to Skip to main content
Licence CPOL
First Posted 4 Aug 2007
Views 30,061
Downloads 945
Bookmarked 20 times

Simple PC Alarm Clock

By | 4 Aug 2007 | Article
A simple PC alarm clock in C# using Visual Basic library to Beep
Screenshot - pcalarmclock.jpg

Introduction

This is a very simple PC alarm clock that can sound the alarm after 1, 2, 3, 4, 5, 10, 15, 20, 30 or 45 minutes. The alarm is a beeping sound at 1 second interval. It is useful if you just want to be reminded of something while using the PC. Maybe you put your kettle on the stove and fear that you may forget. Well, you can use this simple application to remind you.

Background

I know the design could have been better, e.g. using drop down list to enter the duration instead of using buttons, but I was doing this as a challenge to see how fast I can whip up an alarm timer while waiting for my egg on the stove to cook!

// PC Alarm clock by Paul Chin
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PC_AlarmClock
{
   public partial class Form1 : Form
   {
      bool timeup=false;
      int duration = 0,ticks=0;
      
      public Form1()
     {
       InitializeComponent();
     }

     private void button1min_Click(object sender, EventArgs e)
    {
       duration = 60; //secs
       timer1.Start();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
       duration--;
       lblCountdown.Text = duration.ToString();
       if (duration == ticks) timeup = true;

       //To beep, call the Visual Basic library, remember to add a reference to it 
       //in the Reference section of Solution Explorer    
       if(timeup) Microsoft.VisualBasic.Interaction.Beep();
     }
     private void buttonStop_Click(object sender, EventArgs e)
     {
       timer1.Stop();
       duration = 0;
       ticks = 0;
       timeup = false;
     }

    private void button2min_Click(object sender, EventArgs e)
    {
       duration = 60*2; //secs
       timer1.Start();
    }

    private void button3min_Click(object sender, EventArgs e)
    {
       duration = 60*3; //secs
       timer1.Start();
    }

    private void button4min_Click(object sender, EventArgs e)
    {
       duration = 60*4; //secs
       timer1.Start();
    }

   private void button5min_Click(object sender, EventArgs e)
   {
      duration = 60*5; //secs
      timer1.Start();
   }

   private void button10min_Click(object sender, EventArgs e)
   {
      duration = 60*10; //secs
      timer1.Start();
   }

   private void button45_Click(object sender, EventArgs e)
   {
     duration = 60 * 45; //secs
     timer1.Start();
   }

   private void button15min_Click(object sender, EventArgs e)
   {
     duration = 60 * 15; //secs
     timer1.Start();
   }

   private void button20min_Click(object sender, EventArgs e)
   {
     duration = 60 * 20; //secs
     timer1.Start();
   }

   private void button30min_Click(object sender, EventArgs e)
   {
     duration = 60 * 30; //secs
     timer1.Start();
   }

   private void button45min_Click(object sender, EventArgs e)
   {
      duration = 60 * 45; //secs
      timer1.Start();
   }
 }
}

Points of Interest

I could not find the beep sound function in C#, so I had to include a reference to the Microsoft.VisualBasic library and then call it this way:

Microsoft.VisualBasic.Interaction.Beep(); 

You will need to add a reference to it by right-clicking Reference (in your Solution Explorer) then select Add Reference.

History

  • 4th August, 2007: Initial post

License

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

About the Author

Paul Chin PC

Researcher

Malaysia Malaysia

Member

Coder

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThanx PinmemberNitin Sawant3:03 4 Feb '09  
GeneralBeep... PinmemberLandarzar0:14 5 Aug '07  
GeneralFew suggestions PinmemberJared James Sullivan21:30 4 Aug '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 5 Aug 2007
Article Copyright 2007 by Paul Chin PC
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid