■ ICustomImagePainter 인터페이스를 사용해 커스텀 SPLASH SCREEN을 표시하는 방법을 보여준다.
▶ ViewInfo.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 |
using System.Drawing; using DevExpress.Utils.Drawing; using DevExpress.Utils.Text; namespace TestProject { /// <summary> /// 뷰 정보 /// </summary> public class ViewInfo { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 진행 폰트 /// </summary> private Font progressFont = null; /// <summary> /// 브러시 /// </summary> private Brush brush = null; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 단계 - Stage /// <summary> /// 단계 /// </summary> public string Stage { get; set; } #endregion #region 카운터 - Counter /// <summary> /// 카운터 /// </summary> public int Counter { get; set; } #endregion #region 텍스트 - Text /// <summary> /// 텍스트 /// </summary> public string Text { get { return string.Format("{0} - ({1}%)", Stage, Counter.ToString("D2")); } } #endregion #region 진행 레이블 폰트 - ProgressLabelFont /// <summary> /// 진행 레이블 폰트 /// </summary> public Font ProgressLabelFont { get { if(this.progressFont == null) { this.progressFont = new Font("나눔고딕코딩", 10); } return this.progressFont; } } #endregion #region 브러시 - Brush /// <summary> /// 브러시 /// </summary> public Brush Brush { get { if(this.brush == null) { this.brush = new SolidBrush(Color.Black); } return this.brush; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - ViewInfo() /// <summary> /// 생성자 /// </summary> public ViewInfo() { Stage = string.Empty; Counter = 1; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 진행 레이블 위치 계산하기 - CalculateProgressLabelPoint(graphicsCache, boundRectangle) /// <summary> /// 진행 레이블 위치 계산하기 /// </summary> /// <param name="graphicsCache">그래픽스 캐시</param> /// <param name="boundRectangle">경계 사각형</param> /// <returns>진행 레이블 위치</returns> public PointF CalculateProgressLabelPoint(GraphicsCache graphicsCache, Rectangle boundRectangle) { const int yOffset = 40; Size size = TextUtils.GetStringSize(graphicsCache.Graphics, Text, ProgressLabelFont); return new Point(boundRectangle.Width / 2 - size.Width / 2, yOffset); } #endregion } } |
▶ CustomImagePainter.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 |
using System.Drawing; using DevExpress.Utils.Drawing; using DevExpress.Utils.Text; using DevExpress.XtraSplashScreen; namespace TestProject { /// <summary> /// 커스텀 이미지 페인터 /// </summary> class CustomImagePainter : ICustomImagePainter { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 뷰 정보 /// </summary> private ViewInfo viewInfo = null; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 페인터 - Painter /// <summary> /// 페인터 /// </summary> public static CustomImagePainter Painter { get; private set; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Public #region 뷰 정보 - ViewInfo /// <summary> /// 뷰 정보 /// </summary> public ViewInfo ViewInfo { get { if(this.viewInfo == null) { this.viewInfo = new ViewInfo(); } return this.viewInfo; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Static #region 생성자 - CustomImagePainter() /// <summary> /// 생성자 /// </summary> static CustomImagePainter() { Painter = new CustomImagePainter(); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Protected #region 생성자 - CustomImagePainter() /// <summary> /// 생성자 /// </summary> protected CustomImagePainter() { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 그리기 - Draw(graphicsCache, boundRectangle) /// <summary> /// 그리기 /// </summary> /// <param name="graphicsCache">그래픽스 캐시</param> /// <param name="boundRectangle">경계 사각형</param> public void Draw(GraphicsCache graphicsCache, Rectangle boundRectangle) { PointF point = ViewInfo.CalculateProgressLabelPoint(graphicsCache, boundRectangle); graphicsCache.Graphics.DrawString(ViewInfo.Text, ViewInfo.ProgressLabelFont, ViewInfo.Brush, point); } #endregion } } |
▶ Program.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 |
using System; using System.Drawing; using System.Reflection; using System.Windows.Forms; using DevExpress.XtraSplashScreen; namespace TestProject { /// <summary> /// 프로그램 /// </summary> static class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 이미지 구하기 - GetImage() /// <summary> /// 이미지 구하기 /// </summary> /// <returns>이미지</returns> private static Image GetImage() { Assembly assembly = typeof(Program).Assembly; return new Bitmap(assembly.GetManifestResourceStream("TestProject.Images.sample.png")); } #endregion #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Image image = GetImage(); SplashScreenManager.ShowImage(image, true, true, CustomImagePainter.Painter); Application.Run(new MainForm()); } #endregion } } |
▶ 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 |
using System; using System.Windows.Forms; using DevExpress.XtraSplashScreen; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); Initialize(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 로드시 처리하기 - OnLoad(e) /// <summary> /// 로드시 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); SplashScreenManager.HideImage(); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 기본 데이터 로드하기 - LoadBasicData() /// <summary> /// 기본 데이터 로드하기 /// </summary> private void LoadBasicData() { CustomImagePainter.Painter.ViewInfo.Stage = "기본 데이터 로딩"; for(int i = 1; i <= 100; i++) { System.Threading.Thread.Sleep(20); CustomImagePainter.Painter.ViewInfo.Counter = i; SplashScreenManager.Default.Invalidate(); } } #endregion #region 폰트 데이터 로드하기 - LoadFontData() /// <summary> /// 폰트 데이터 로드하기 /// </summary> private void LoadFontData() { CustomImagePainter.Painter.ViewInfo.Stage = "폰트 데이터 로딩"; for(int i = 1; i <= 100; i++) { System.Threading.Thread.Sleep(20); CustomImagePainter.Painter.ViewInfo.Counter = i; SplashScreenManager.Default.Invalidate(); } } #endregion #region 텍스처 데이터 로드하기 - LoadTextureData() /// <summary> /// 텍스처 데이터 로드하기 /// </summary> private void LoadTextureData() { CustomImagePainter.Painter.ViewInfo.Stage = "텍스처 데이터 로딩"; for(int i = 1; i <= 100; i++) { System.Threading.Thread.Sleep(20); CustomImagePainter.Painter.ViewInfo.Counter = i; SplashScreenManager.Default.Invalidate(); } } #endregion #region 초기화 하기 - Initialize() /// <summary> /// 초기화 하기 /// </summary> protected void Initialize() { LoadBasicData(); LoadFontData(); LoadTextureData(); } #endregion } } |