■ 알림 창 만들기
------------------------------------------------------------------------------------------------------------------------
▶ MainForm.cs
using System; using System.Drawing; using System.Timers; using System.Windows.Forms;
using TestProject.Properties;
namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Delegate ////////////////////////////////////////////////////////////////////////////////////////// Private
#region 높이/위쪽 위치 설정하기 대리자 - SetHeightTopDelegate(flag)
/// <summary> /// 높이/위쪽 위치 설정하기 대리자 /// </summary> /// <param name="flag">플래그</param> private delegate void SetHeightTopDelegate(int flag);
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary> /// 높이/위쪽 위치 설정하기 대리자 /// </summary> private SetHeightTopDelegate setHeightTopDelegate = null;
/// <summary> /// 타이머 /// </summary> private System.Timers.Timer timer;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - NoticeForm()
/// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent();
this.closePictureBox.Image = Resources.close_normal;
this.closePictureBox.Click += closePictureBox_Click; this.closePictureBox.MouseDown += closePictureBox_MouseDown; this.closePictureBox.MouseMove += closePictureBox_MouseMove; this.closePictureBox.MouseLeave += closePictureBox_MouseLeave; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event
#region 폼 로드시 처리하기 - Form_Load(sender, e)
/// <summary> /// 폼 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Form_Load(object sender, EventArgs e) { setHeightTopDelegate = new SetHeightTopDelegate(SetHeightTop);
Size = new Size(170, 0); Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - Width - 20, Screen.PrimaryScreen.WorkingArea.Height - Height);
this.timer = new System.Timers.Timer(2);
this.timer.Elapsed += timer_Elapsed_PopUp;
this.timer.Start(); }
#endregion #region 닫기 픽쳐 박스 클릭시 처리하기 - closePictureBox_Click(sender, e)
/// <summary> /// 닫기 픽처 박스 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void closePictureBox_Click(object sender, EventArgs e) { Close(); }
#endregion #region 닫기 픽쳐 박스 마우스 DOWN 처리하기 - closePictureBox_MouseDown(sender, e)
/// <summary> /// 닫기 픽쳐 박스 마우스 DOWN 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void closePictureBox_MouseDown(object sender, MouseEventArgs e) { this.closePictureBox.Image = Resources.close_down; }
#endregion #region 닫기 픽쳐 박스 마우스 이동시 처리하기 - closePictureBox_MouseMove(sender, e)
/// <summary> /// 닫기 픽쳐 박스 마우스 이동시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void closePictureBox_MouseMove(object sender, MouseEventArgs e) { this.closePictureBox.Image = Resources.close_over; }
#endregion #region 닫기 픽쳐 박스 마우스 이탈시 처리하기 - closePictureBox_MouseLeave(sender, e)
/// <summary> /// 닫기 픽쳐 박스 마우스 이탈시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void closePictureBox_MouseLeave(object sender, EventArgs e) { this.closePictureBox.Image = Resources.close_normal; }
#endregion
#region 타이머 경과시 처리하기 (팝업용) - timer_Elapsed_PopUp(sender, e)
/// <summary> /// 타이머 경과시 처리하기 (팝업용) /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void timer_Elapsed_PopUp(object sender, ElapsedEventArgs e) { if(Height < 120) { Invoke(setHeightTopDelegate, 0); } else { this.timer.Stop();
this.timer.Elapsed -= timer_Elapsed_PopUp; this.timer.Elapsed += timer_Elapsed_PopOut;
this.timer.Interval = 3000;
this.timer.Start(); }
Application.DoEvents(); }
#endregion #region 타이머 경과시 처리하기 (팝아웃용) - timer_Elapsed_PopOut(sender, e)
/// <summary> /// 타이머 경과시 처리하기 (팝아웃용) /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void timer_Elapsed_PopOut(object sender, ElapsedEventArgs e) { while(Height > 2) { Invoke(setHeightTopDelegate, 1); }
this.timer.Stop();
Application.DoEvents();
Invoke(setHeightTopDelegate, 2); }
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 높이/위쪽 위치 설정하기 - SetHeightTop(flag)
/// <summary> /// 높이/위쪽 위치 설정하기 /// </summary> /// <param name="flag">플래그</param> private void SetHeightTop(int flag) { if(flag == 0) { Height++;
Top--; } else if(flag == 1) { Height--;
Top++; } else if(flag == 2) { Close(); } }
#endregion } }
|
------------------------------------------------------------------------------------------------------------------------
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] WebBrowser 클래스 : DocumentCompleted 이벤트를 사용해 웹 문서 로드 완료시 처리하기 (0) | 2017.01.15 |
---|---|
[C#/WINFORM] WebBrowser 클래스 : DocumentCompleted 이벤트를 사용해 웹 문서 로드 완료시 처리하기 (0) | 2017.01.15 |
[C#/WINFORM] 스크린 세이버(Screen Saver) 만들기 (0) | 2017.01.15 |
[C#/WINFORM] 커스텀 메시지 박스 사용하기 (0) | 2017.01.15 |
[C#/WINFORM] Control 클래스 : MouseDown/MouseMove/MouseUp 이벤트를 사용해 도형 그리기 (0) | 2017.01.10 |
[C#/WINFORM] 알림 창 만들기 (0) | 2017.01.10 |
[C#/WINFORM] 폼 강제로 칠하기 (0) | 2016.12.14 |
[C#/WINFORM] 전체 화면 그래픽스 객체 구하기 (0) | 2016.12.14 |
[C#/WINFORM] Application 클래스 : 애플리케이션 실행 경로 구하기 (0) | 2016.12.11 |
[C#/WINFORM] Application 클래스 : ThreadException 이벤트를 사용해 예외 처리하기 (0) | 2016.12.04 |
[C#/WINFORM] 비트맵으로 커서 만들기 (0) | 2016.08.30 |
댓글을 달아 주세요