C# Tutorial - Create A Youtube Alarm Clock in Visual Studio
C# Tutorial - Create A Youtube Alarm Clock in Visual Studio
In this tutorial we will create a simple yet elegant YouTube alarm clock in Visual Studio using C# programming language.
The main idea for this alarm clock is to use a custom GUI, transparent form and custom font in the application. We have
our own custom font for this alarm clock and we will import it in for this application. You can use any of your favourite
YouTube videos to wake you up in the Morning, now isn't that the dream. We have created a simple GUI image for the
application, download it from below to follow along with this tutorial.
Lesson Objective -
Start Visual Studio and create a new windows form application under C# programming language. Call this project YouTube
Alarm Clock.
Click OK.
While the form is selected please change the following to the properties
Final Result
Now debug the program and see the result of the settings we done to it.
Click on the start button to start debugging also you can press F5. Now you will not see
the close button in the form but you can still close it from the task bar, right click on the application in the task bar then
click on Close.
Like what you see yet. Now let's add the custom font but we need to copy and paste the file in the Debug folder first.
Right click on the name of the project in the solutions explorer and click on
Open Folder in File Explorer
Now drag and drop a Date Time Picker from the tool box on to the green section
Drag and drop a Date Timer Picker from the tool box to the form. Drag it to the green
section of the Alarm Clock.
Change the following in the properties of the Date and Time Picker
Format - Time
Next up, Drag and drop a web browser from the tool box, this component will be used to play the music video from you
tube in the program.
Drag and drop a Text Box from the tool box, this will be used to paste the you tube video link in the application. Place it
above the web browser.
name - youtubelink
Add a button to the form from the tool box. Since we are using a frameless window for this alarm clock, we will use this
button to close the alarm clock.
Name - exitButton
Location - 1095, 27
Size - 48, 35
Now lets add a timer to the project, from the tool box drag and drop a Timer in the Form.
Name - clockTimer
Enabled - True
Interval - 1000
Select the Form and make sure no other components are selected, lets add some events to the form
To find the Events Windows, click on the lightning bolt icon in the properties window.
In the load option type LoadForm and press enter. This will take you to the code
view, come back to the design view and the click on the Exit Button.
Find the Click event and type exitAlarm and press enter.
Find the Value Changed option and type timerChanged and press enter.
Now we can start coding this whole thing up and the fun begins here
using System;
using System.Collections.Generic;
namespace YouTube_Alarm_Clock
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
}
This is what the code looks like so far, now we need to add some our own instructions to it.
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.Drawing.Text;
namespace YouTube_Alarm_Clock
{
public partial class Form1 : Form
{
bool alarmed = false; // this boolean will check if the alarm has gone off
public Form1()
{
InitializeComponent();
}
}
}
}
Using System.Drawing.Text; is the class we need to load up the custom font we pasted in the project folder earlier.
bool alarmed = false; this boolean will be used to check if the alarm was set off or not.
Lets add the following in the Load Form function. All the codes are explain the green text
//These are comments, we use comments to explain the codes. Use a double slashes to enter single line
comment.
// we are setting the colour and the transparency key for the form
this.BackColor = System.Drawing.Color.Gray;
this.TransparencyKey = System.Drawing.Color.Gray;
The double slashes are single line comments but when you use /** we are able to use multi line comment this also ends
in with this **/
// create a another date time class this will be used to set the alarm time
DateTime userTime = dateTimePicker1.Value;
/**
* Below is the if statement which will check if the time
* Matches the user time then we will set the alarm
* If the current DAY equals to users DAY
* AND
* if the current Month equals the users Month
* AND
* if the current hour equals the users hour
* AND
* if the current minute equals the users minute
* AND
* alarmed boolean is true
* Then we will follow the instructions inside the if statement
**/
}
}
Woohoo it works.
If you have followed the tutorial this far then well done, if there are any errors refer back to the code and check against
your to spot any mistakes.
Moo Out.