Click here to Skip to main content
Click here to Skip to main content

Simple PC Alarm Clock

, 4 Aug 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Paul Chin PC
Researcher
Malaysia Malaysia
Coder

Comments and Discussions

 
GeneralThanx PinmemberNitin Sawant4-Feb-09 3:03 
GeneralBeep... PinmemberLandarzar5-Aug-07 0:14 
GeneralFew suggestions PinmemberJared James Sullivan4-Aug-07 21:30 

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.

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 5 Aug 2007
Article Copyright 2007 by Paul Chin PC
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid