Recently, I was very busy. The teacher forgot some things and turned to the computer all day. So I wanted to remind myself to be a C # winform.ProgramTrainer!
The alarm function I implemented is relatively simple. I mainly used the timer Timer control and referenced the system during the alarm. media namespace, playing wav files, tried to play only this type of files. I don't know if I can play MP3. Currently I won't, mainlyCodeAs follows:
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 the ringtone Cmbring. items. add ("step by step music .wav"); cmbring. items. add ("background music .wav");} private void timer1_tick (Object sender, eventargs e) {timer1.interval = 1000; lblnow. TEXT = datetime. now. tostring ();} private void btnpreview_click (Object sender, eventargs e) {If (string. isnullorempty (cmbring. text) {MessageBox. show ("select the playing ringtone !! "); Return;} playsound () ;}/// <summary> // play the wav sound file /// </Summary> private void playsound () {// use the new instance point soundlocation to specify the name of the music player to be played. soundlocation = cmbring. text; // (put the playing music in the application DEBUG directory) player. load (); // player for music playback. 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) {playsound (); // After enabling timer2.stop ();}} private void btnstop_click (Object sender, eventargs e) {timer2.stop (); player. stop ();}}}
Download all source code of this program!
Download the attachment:
- Alarmclcok.rar (3.5 MB)
Existing0People comment, slam->Here<-Participate in the discussion
Iteye recommendation
- -Software talents free of language and low guarantee paid study in the United States! -