■ SplashScreenManager 클래스에서 커스텀 오버레이 폼을 사용하는 방법을 보여준다.
▶ MainForm.cs
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
using System; using System.Drawing; using System.Threading.Tasks; using System.Windows.Forms; using DevExpress.XtraEditors; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 오버레이 폼 헬퍼 1 /// </summary> private OverlayFormHelper helper1 = null; /// <summary> /// 오버레이 폼 헬퍼 2 /// </summary> private OverlayFormHelper helper2 = null; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); FormClosing += Form_FormClosing; this.button1.Click += button1_Click; this.button2.Click += button2_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 폼을 닫을 경우 처리하기 - Form_FormClosing(sender, e) /// <summary> /// 폼을 닫을 경우 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Form_FormClosing(object sender, FormClosingEventArgs e) { this.helper1?.Close(); this.helper1 = null; this.helper2?.Close(); this.helper2 = null; } #endregion #region 버튼 1 클릭시 처리하기 - button1_Click(sender, e) /// <summary> /// 버튼 1 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private async void button1_Click(object sender, EventArgs e) { this.helper1 = new OverlayFormHelper(this.panelControl1, OverlayFormHelper.DefaultFont12, Color.Black, true, -30, 0); try { this.helper1.Show(); this.helper1.SetMessage("작업 1 처리중..."); await Task.Run ( async () => { await Task.Delay(5000, this.helper1.CancellationTokenSource.Token); }, this.helper1.CancellationTokenSource.Token ); } catch(Exception exception) { if(exception is TaskCanceledException) { XtraMessageBox.Show(this, "작업 1이 취소되었습니다.", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { } } finally { this.helper1?.Close(); this.helper1 = null; } } #endregion #region 버튼 2 클릭시 처리하기 - button2_Click(sender, e) /// <summary> /// 버튼 2 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private async void button2_Click(object sender, EventArgs e) { this.helper2 = new OverlayFormHelper(this.panelControl2, OverlayFormHelper.DefaultFont12, Color.Black, true, -30, 0); try { this.helper2.Show(); this.helper2.SetMessage("작업 2 처리중..."); await Task.Run ( async () => { await Task.Delay(5000, this.helper2.CancellationTokenSource.Token); }, this.helper2.CancellationTokenSource.Token ); } catch(Exception exception) { if(exception is TaskCanceledException) { XtraMessageBox.Show(this, "작업 2가 취소되었습니다.", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { } } finally { this.helper2?.Close(); this.helper2 = null; } } #endregion } } |