■ SplashScreenManager 클래스의 ShowImage 정적 메소드를 사용해 스플래시 스크린 이미지를 표시하는 방법을 보여준다.
▶ 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 font = 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 폰트 - Font /// <summary> /// 폰트 /// </summary> public Font Font { get { if(this.font == null) { this.font = new Font("Consolas", 10); } return this.font; } } #endregion #region 브러시 - Brush /// <summary> /// 브러시 /// </summary> public Brush Brush { get { if(this.brush == null) { this.brush = new SolidBrush(Color.Black); } return this.brush; } } #endregion #region 텍스트 - Text /// <summary> /// 텍스트 /// </summary> public string Text { get { return string.Format("{0} - ({1}%)", Stage, Counter.ToString("D2")); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - ViewInfo() /// <summary> /// 생성자 /// </summary> public ViewInfo() { Stage = string.Empty; Counter = 1; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 진행 레이블 포인트 구하기 - GetProgressLabelPoint(graphicsCache, boundRectangle) /// <summary> /// 진행 레이블 포인트 구하기 /// </summary> /// <param name="graphicsCache">그래픽스 캐시</param> /// <param name="boundRectangle">경계 사각형</param> /// <returns>진행 레이블 포인트</returns> public PointF GetProgressLabelPoint(GraphicsCache graphicsCache, Rectangle boundRectangle) { const int yOffset = 40; Size size = TextUtils.GetStringSize(graphicsCache.Graphics, Text, Font); return new Point(boundRectangle.Width / 2 - size.Width / 2, yOffset); } #endregion } } |
▶ SplashImagePainter.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 |
using System.Drawing; using DevExpress.Utils.Drawing; using DevExpress.XtraSplashScreen; namespace TestProject { /// <summary> /// 스플래시 이미지 페인터 /// </summary> class SplashImagePainter : ICustomImagePainter { ////////////////////////////////////////////////////////////////////////////////////////// Field //////////////////////////////////////////////////////////////////////////////// Instance ////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 뷰 정보 /// </summary> private ViewInfo viewInfo = null; #endregion ////////////////////////////////////////////////////////////////////////////////////////// Property //////////////////////////////////////////////////////////////////////////////// Static ////////////////////////////////////////////////////////////////////// Public #region 페인터 - Painter /// <summary> /// 페인터 /// </summary> public static SplashImagePainter 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 SplashImagePainter() /// <summary> /// 생성자 /// </summary> static SplashImagePainter() { Painter = new SplashImagePainter(); } #endregion //////////////////////////////////////////////////////////////////////////////// Instance ////////////////////////////////////////////////////////////////////// Protected #region 생성자 - SplashImagePainter() /// <summary> /// 생성자 /// </summary> protected SplashImagePainter() { } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Method //////////////////////////////////////////////////////////////////////////////// Instance ////////////////////////////////////////////////////////////////////// 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.GetProgressLabelPoint(graphicsCache, boundRectangle); graphicsCache.Graphics.DrawString(ViewInfo.Text, ViewInfo.Font, ViewInfo.Brush, point); } #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 129 130 |
using System; using System.Threading; 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(); InitializeTask(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Methid ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 로드시 처리하기 - OnLoad(e) /// <summary> /// 로드시 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); SplashScreenManager.HideImage(); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 작업 초기화 하기 #1 - InitializeTask1() /// <summary> /// 작업 초기화 하기 #1 /// </summary> private void InitializeTask1() { SplashImagePainter.Painter.ViewInfo.Stage = "변수 생성"; for(int i = 1; i <= 100; i++) { Thread.Sleep(20); SplashImagePainter.Painter.ViewInfo.Counter = i; SplashScreenManager.Default.Invalidate(); } } #endregion #region 작업 초기화 하기 #2 - InitializeTask2() /// <summary> /// 작업 초기화 하기 #2 /// </summary> private void InitializeTask2() { SplashImagePainter.Painter.ViewInfo.Stage = "폰트 로딩"; for(int i = 1; i <= 100; i++) { Thread.Sleep(20); SplashImagePainter.Painter.ViewInfo.Counter = i; SplashScreenManager.Default.Invalidate(); } } #endregion #region 작업 초기화 하기 #3 - InitializeTask3() /// <summary> /// 작업 초기화 하기 #3 /// </summary> private void InitializeTask3() { SplashImagePainter.Painter.ViewInfo.Stage = "텍스처 로딩"; for(int i = 1; i <= 100; i++) { Thread.Sleep(20); SplashImagePainter.Painter.ViewInfo.Counter = i; SplashScreenManager.Default.Invalidate(); } } #endregion #region 작업 초기화 하기 - InitializeTask() /// <summary> /// 작업 초기화 하기 /// </summary> private void InitializeTask() { InitializeTask1(); InitializeTask2(); InitializeTask3(); } #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 56 |
using System; using System.Drawing; using System.Reflection; using System.Windows.Forms; using DevExpress.XtraSplashScreen; namespace TestProject { /// <summary> /// 프로그램 /// </summary> class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> [STAThread] private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Image image = GetImage(); SplashScreenManager.ShowImage(image, true, true, SplashImagePainter.Painter); Application.Run(new MainForm()); } #endregion #region 이미지 구하기 - GetImage() /// <summary> /// 이미지 구하기 /// </summary> /// <returns>이미지</returns> private static Image GetImage() { Assembly assembly = typeof(Program).Assembly; return new Bitmap(assembly.GetManifestResourceStream("TestProject.Image.sample.png")); } #endregion } } |