개발/C#
# 알람 시계 만들기
노마드
2021. 1. 25. 08:15
21시 5분 50초가 되면, playSimpleSound() 메서드를 호출하여 알람 소리를 발생시킨다.
using System;
using System.Windows.Forms;
using System.Media;
namespace AlarmProgram {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
timer1.Enabled = true;
timer1.Interval = 1000;
timer1.Tick += timer1_Tick;
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
if(DateTime.Now.Hour == 21 && DateTime.Now.Minute == 5 && DateTime.Now.Second == 50)
{
playSimpleSound();
}
}
private void playSimpleSound()
{
SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\user\Desktop\alarm.wav");
simpleSound.Play();
}
}
}