C # small alarm clock V2.0

Source: Internet
Author: User

In the last article, I added a functional interface for browsing local WAV Files with slight changes.

ProgramCode

View code

 Using  System;
Using System. Windows. forms;
Using System. Media;

Namespace Alarmclock
{
Public Partial Class Form1: Form
{
Public Form1 ()
{
Initializecomponent ();
}
Soundplayer player = New Soundplayer ();

Private Void Form1_load ( Object Sender, eventargs E)
{
Timer1.start ();
// Bind to ComboBox
For ( Int I = 0 ; I <= 23 ; I ++ )
{
Cmbhour. Items. Add (I );
}
For ( Int J = 0 ; J < 60 ; J ++ )
{
Cmbminute. Items. Add (j );
}
// Bind ringtone
Cmbring. Items. Add ( " BBK music .wav " );
Cmbring. Items. Add ( " Background Music .wav " );
}

Private Void Timereffectick ( Object Sender, eventargs E)
{
Timer1.interval = 1000 ;
Lblnow. Text = Datetime. Now. tostring ();
}

Private Void Btnpreview_click ( Object Sender, eventargs E)
{
Playjudge ();
}
/// <Summary>
/// Determine whether the local playback is provided by the system
/// </Summary>
Private Void Playjudge ()
{
If (Cmbring. Text = "" && Txtupload. Text = "" )
{
MessageBox. Show ( " Select system ringtones or local ringtones " );
Return ;
}
If (Cmbring. Text = "" | Txtupload. Text ! = "" )
{
Playsound (txtupload. Text );
}
If (Cmbring. Text ! = "" | Txtupload. Text = "" )
{
Playsound (cmbring. Text );
}
}
/// <Summary>
/// Play WAV audio files
/// </Summary>
Private Void Playsound ( String Path)
{
// Use the new instance point soundlocation to specify the name of the music to be played.
Player. soundlocation = Path; // (Put the playing music in the application DEBUG directory)
Player. Load ();
// Play Music
Player. Play ();
}

Private Void Btnopen_click ( Object Sender, eventargs E)
{
If (Cmbhour. Text = "" && Cmbminute. Text = "" )
{
MessageBox. Show ( " No alert time set " );
Return ;
}
Timer2.start ();
}

Private Void Timer2_tick ( Object Sender, eventargs E)
{
Timer2.interval = 1000 ;
String H = Cmbhour. text;
String M = Cmbminute. text;
String Nowh = Datetime. Now. Hour. tostring ();
String Nowm = Datetime. Now. Minute. tostring ();
If (H = Nowh && M = Nowm)
{
Playjudge ();
// Stop threads after enabling
Timer2.stop ();
}
}

Private Void Btnstop_click ( Object Sender, eventargs E)
{
Timer2.stop ();
Player. Stop ();
}
/// <Summary>
/// Browse local ringtones
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private Void Button#click ( Object Sender, eventargs E)
{
// Determine whether the "open file dialog box" is opened"
If (Openfiledialog1.showdialog () = Dialogresult. OK)
{
String File = Openfiledialog1.filename;
If (File ! = Null )
{
// Determine whether the uploaded file is a WAV ringtone
// D: \ winformtest \ alarmclcok \ myclock \ bin \ debug \ BBK .wav
String Fileextend = File. substring (file. lastindexof ( " . " ) + 1 ). Tostring (). tolower ();
If (Fileextend ! = " Wav " )
{
MessageBox. Show ( " Select a WAV file. " );
Return ;
}
Txtupload. Text = File;
}
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.