# 알람 시계 만들기

2021. 1. 25. 08:15개발/C#

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();

    }

  }

}

'개발 > C#' 카테고리의 다른 글

# 구독자 조회 프로그램 예제  (0) 2021.01.25
# 메뉴 고르기 프로그램 예제 코드  (0) 2021.01.25
# 콘솔 창 숨기는 방법  (0) 2021.01.25
# 네이버 크롤러 예제 코드  (0) 2021.01.25
# CodeLens (코드렌즈)  (0) 2021.01.25