[C# 윈폼] C# 윈폼으로 Alarm(알람) 창 만들기


안녕하세요.

 

오늘은 C# 윈폼에서 간단히 Alarm 창을 만들어 보려고 합니다.

 

C# 에서는 MessageBox 라고 하여 이미 대화상자를 제공해 주지만, 저는 간단히 시각적으로 효과를 주기 위해 알람창을 빨간색 배경으로 깜빡깜빡 하게 하여 시각적인 효과를 주는 화면을 만들어 보려고 합니다.

 

그럼 바로 예제 프로그램을 만들어 보도록 하겠습니다.


 

먼저, 윈폼 프로젝트를 생성해 주시고 아래와 같이 Lable 컨트롤과 Panel 컨트롤을 배치해 주시기 바랍니다.


윈폼 프로젝트 생성 및 컨트롤 배치



현재 Panel 컨트롤은 Dock = Fill 상태 입니다!


그럼 바로 예제코드를 작성해 보도록 하겠습니다.


예제 코드


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

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;

 

namespace AlarmTest

{

    public partial class Form1 : Form

    {

        Timer timer = new Timer();

        int count = 0;

 

        public Form1()

        {

            InitializeComponent();

 

            this.Load += AlarmForm_Load;

        }

 

        public void AlarmForm_Load(object sender, EventArgs e)

        {

            timer.Interval = 500;

            timer.Tick += new EventHandler(timer_Tick);

            timer.Start();

        }

 

        private void timer_Tick(object sender, EventArgs e)

        {

            count++;

 

            if(count % 2 == 0)

            {

                uiPn_Alarm.BackColor = Color.Green;

            }

            else

            {

                uiPn_Alarm.BackColor = Color.Red;

            }

        }

    }

}

 

Colored by Color Scripter

cs


실행 결과



 

위와 같이 0.5초 간격으로 배경화면이 흰색 -> 빨강 -> 흰색 이렇게 번갈아 가면서 알람창이 실행된 것을 확인하실 수 있습니다.

 

감사합니다~~


728x90

이 글을 공유하기

댓글

Designed by JB FACTORY