■ 투명 배경의 스플래시 이미지를 사용하는 방법을 보여준다.
▶ BitmapHelper.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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
using System; using System.Drawing; using System.Drawing.Imaging; namespace TestProject { /// <summary> /// 비트맵 헬퍼 /// </summary> public unsafe class BitmapHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Struct ////////////////////////////////////////////////////////////////////////////////////////// Private #region 픽셀 데이터 - PixelData /// <summary> /// 픽셀 데이터 /// </summary> private struct PixelData { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 파란색 /// </summary> public byte Blue; /// <summary> /// 녹색 /// </summary> public byte Green; /// <summary> /// 빨간색 /// </summary> public byte Red; /// <summary> /// 알파 /// </summary> public byte Alpha; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns>문자열</returns> public override string ToString() { return "(" + Alpha.ToString() + ", " + Red.ToString() + ", " + Green.ToString() + ", " + Blue.ToString() + ")"; } #endregion } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 비트맵 /// </summary> private Bitmap bitmap = null; /// <summary> /// 비트맵 너비 /// </summary> private int bitmapWidth = 0; /// <summary> /// 비트맵 데이터 /// </summary> private BitmapData bitmapData = null; /// <summary> /// 베이스 포인터 /// </summary> private Byte* basePointer = null; /// <summary> /// 픽셀 데이터 /// </summary> private PixelData* pixelData = null; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - BitmapHelper(bitmap) /// <summary> /// 생성자 /// </summary> /// <param name="bitmap">비트맵</param> public BitmapHelper(Bitmap bitmap) { this.bitmap = bitmap; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 비트맵 잠그기 - LockBitmap() /// <summary> /// 비트맵 잠그기 /// </summary> public void LockBitmap() { Rectangle rectangle = new Rectangle(Point.Empty, this.bitmap.Size); this.bitmapWidth = (int)(rectangle.Width * sizeof(PixelData)); if(this.bitmapWidth % 4 != 0) { this.bitmapWidth = 4 * (this.bitmapWidth / 4 + 1); } this.bitmapData = this.bitmap.LockBits(rectangle, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); this.basePointer = (Byte*)this.bitmapData.Scan0.ToPointer(); } #endregion #region 픽셀 구하기 - GetPixel(int x, int y) /// <summary> /// 픽셀 구하기 /// </summary> /// <param name="x">X 좌표</param> /// <param name="y">Y 좌표</param> /// <returns>색상</returns> public Color GetPixel(int x, int y) { this.pixelData = (PixelData*)(this.basePointer + y * this.bitmapWidth + x * sizeof(PixelData)); return Color.FromArgb(this.pixelData->Alpha, this.pixelData->Red, this.pixelData->Green, this.pixelData->Blue); } #endregion #region 다음 픽셀 구하기 - GetPixelNext() /// <summary> /// 다음 픽셀 구하기 /// </summary> /// <returns>색상</returns> public Color GetPixelNext() { this.pixelData++; return Color.FromArgb(this.pixelData->Alpha, this.pixelData->Red, this.pixelData->Green, this.pixelData->Blue); } #endregion #region 픽셀 설정하기 - SetPixel(x, y, color) /// <summary> /// 픽셀 설정하기 /// </summary> /// <param name="x">X 좌표</param> /// <param name="y">Y 좌표</param> /// <param name="color">색상</param> public void SetPixel(int x, int y, Color color) { PixelData* pixelData = (PixelData*)(this.basePointer + y * this.bitmapWidth + x * sizeof(PixelData)); pixelData->Alpha = color.A; pixelData->Red = color.R; pixelData->Green = color.G; pixelData->Blue = color.B; } #endregion #region 비트맵 잠금 해제하기 - UnlockBitmap() /// <summary> /// 비트맵 잠금 해제하기 /// </summary> public void UnlockBitmap() { this.bitmap.UnlockBits(this.bitmapData); this.bitmapData = null; this.basePointer = null; } #endregion } } |
▶ TransparentSplashControl.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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 |
using System; using System.Drawing; using System.Drawing.Text; using System.Runtime.InteropServices; using System.Windows.Forms; namespace TestProject { /// <summary> /// 투명 스플래시 컨트롤 /// </summary> public sealed class TransparentSplashControl : Control { //////////////////////////////////////////////////////////////////////////////////////////////////// Import ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 데스크톱 윈도우 구하기 - GetDesktopWindow() /// <summary> /// 데스크톱 윈도우 구하기 /// </summary> /// <returns>데스크톱 윈도우 핸들</returns> [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr GetDesktopWindow(); #endregion #region 부모 설정하기 - SetParent(childHandle, parentHandle) /// <summary> /// 부모 설정하기 /// </summary> /// <param name="childHandle">자식 핸들</param> /// <param name="parentHandle">부모 핸들</param> /// <returns>처리 결과</returns> [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SetParent(IntPtr childHandle, IntPtr parentHandle); #endregion #region 윈도우 위치 설정하기 - SetWindowPos(windowHandle, windowHandleInsertAfter, x, y, width, height, flag) /// <summary> /// 윈도우 위치 설정하기 /// </summary> /// <param name="windowHandle">윈도우 핸들</param> /// <param name="windowHandleInsertAfter">추가할 윈도우의 앞에 오는 윈도우 핸들</param> /// <param name="x">X 좌표</param> /// <param name="y">Y 좌표</param> /// <param name="width">너비</param> /// <param name="height">높이</param> /// <param name="flag">플래그</param> /// <returns>처리 결과</returns> [DllImport("user32.dll", EntryPoint = "SetWindowPos", CallingConvention = CallingConvention.StdCall, SetLastError = true)] private static extern int SetWindowPos(IntPtr windowHandle, IntPtr windowHandleInsertAfter, int x, int y, int width, int height, uint flag); #endregion #region 비트맵 복사하기 - BitBlt(targetDCHandle, targetX, targetY, width, height, sourceDCHandle, sourceX, sourceY, ropFlag) /// <summary> /// 비트맵 복사하기 /// </summary> /// <param name="targetDCHandle">타겟 디바이스 컨텍스트 핸들</param> /// <param name="targetX">타겟 X 좌표</param> /// <param name="targetY">타겟 Y 좌표</param> /// <param name="width">너비</param> /// <param name="height">높이</param> /// <param name="sourceDCHandle">소스 디바이스 컨텍스트 핸들</param> /// <param name="sourceX">소스 X 좌표</param> /// <param name="sourceY">소스 Y 좌표</param> /// <param name="ropFlag">래스터 연산 플래그</param> /// <returns>처리 결과</returns> [DllImport("gdi32.dll")] private static extern bool BitBlt(IntPtr targetDCHandle, int targetX, int targetY, int width, int height, IntPtr sourceDCHandle, int sourceX, int sourceY, uint ropFlag); #endregion #region 픽셀 설정하기 - SetPixel(dcHandle, x, y, color) /// <summary> /// 픽셀 설정하기 /// </summary> /// <param name="dcHandle">디바이스 컨텍스트 핸들</param> /// <param name="x">X 좌표</param> /// <param name="y">Y 좌표</param> /// <param name="color">색상</param> /// <returns>실제 설정 색상</returns> [DllImport("gdi32.dll")] private static extern uint SetPixel(IntPtr dcHandle, int x, int y, uint color); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 인스턴스 /// </summary> private static TransparentSplashControl _instance; /// <summary> /// 잠금 객체 /// </summary> private static object _lockObject = new object(); #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// WS_EX_TOPMOST /// </summary> private const int WS_EX_TOPMOST = unchecked((int)0x00000008L); /// <summary> /// WS_EX_TOOLWINDOW /// </summary> private const int WS_EX_TOOLWINDOW = unchecked((int)0x00000080); /// <summary> /// SWP_NOSIZE /// </summary> private const uint SWP_NOSIZE = 0x0001; /// <summary> /// SWP_NOMOVE /// </summary> private const uint SWP_NOMOVE = 0x0002; /// <summary> /// HWND_TOPMOST /// </summary> private const int HWND_TOPMOST = -1; /// <summary> /// 제목 /// </summary> private string title; /// <summary> /// 주석 /// </summary> private string comment; /// <summary> /// 문자열 포맷 /// </summary> private StringFormat stringFormat; /// <summary> /// 텍스트 오프셋 X /// </summary> private int textOffsetX; /// <summary> /// 텍스트 오프셋 Y /// </summary> private int textOffsetY; /// <summary> /// 리딩 /// </summary> private int leading; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 인스턴스 - Instance /// <summary> /// 인스턴스 /// </summary> public static TransparentSplashControl Instance { get { lock(_lockObject) { if(_instance == null || _instance.IsDisposed) { _instance = new TransparentSplashControl(); } return _instance; } } } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Public #region 제목 - Title /// <summary> /// 제목 /// </summary> public string Title { get { return this.title; } set { if(this.title != value) { this.title = value; Invalidate ( new Rectangle ( Convert.ToInt32(TitleRectangle.X), Convert.ToInt32(TitleRectangle.Y), TextAreaWidth, Convert.ToInt32(TitleRectangle.Height) ) ); Update(); } } } #endregion #region 주석 - Comment /// <summary> /// 주석 /// </summary> public string Comment { get { return this.comment; } set { if(this.comment != value) { this.comment = value; Invalidate ( new Rectangle ( Convert.ToInt32(CommentRectangle.X), Convert.ToInt32(CommentRectangle.Y), TextAreaWidth, Convert.ToInt32(CommentRectangle.Height) ) ); Update(); } } } #endregion #region 텍스트 영역 X - TextAreaX /// <summary> /// 텍스트 영역 X /// </summary> public int TextAreaX { get; set; } #endregion #region 텍스트 영역 Y - TextAreaY /// <summary> /// 텍스트 영역 Y /// </summary> public int TextAreaY { get; set; } #endregion #region 텍스트 영역 너비 - TextAreaWidth /// <summary> /// 텍스트 영역 너비 /// </summary> public int TextAreaWidth { get; set; } #endregion #region 텍스트 영역 높이 - TextAreaHeight /// <summary> /// 텍스트 영역 높이 /// </summary> public int TextAreaHeight { get; set; } #endregion #region 투명 색상 - TransparencyColor /// <summary> /// 투명 색상 /// </summary> public Color TransparencyColor { get; set; } #endregion #region 제목 사각형 - TitleRectangle /// <summary> /// 제목 사각형 /// </summary> private RectangleF TitleRectangle { get; set; } #endregion #region 주석 사각형 - CommentRectangle /// <summary> /// 주석 사각형 /// </summary> private RectangleF CommentRectangle { get; set; } #endregion #region 주석 폰트 - CommentFont /// <summary> /// 주석 폰트 /// </summary> public Font CommentFont { get; set; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 생성 매개 변수 - CreateParams /// <summary> /// 생성 매개 변수 /// </summary> protected override CreateParams CreateParams { get { CreateParams createParams = base.CreateParams; createParams.ExStyle |= WS_EX_TOOLWINDOW | WS_EX_TOPMOST; createParams.Parent = IntPtr.Zero; return createParams; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Private #region 생성자 - TransparentSplashControl() /// <summary> /// 생성자 /// </summary> private TransparentSplashControl() { Title = string.Empty; Comment = string.Empty; Font = new Font("Verdana", 28.00f, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))); CommentFont = new Font("Verdana", 8.25f , FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))); SetStyle(ControlStyles.DoubleBuffer , false); SetStyle(ControlStyles.UserPaint , true ); SetStyle(ControlStyles.AllPaintingInWmPaint, true ); this.stringFormat = new StringFormat(); this.stringFormat.FormatFlags |= StringFormatFlags.NoWrap; this.stringFormat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces; this.textOffsetY = 0; this.textOffsetX = 10; this.leading = 6; Visible = false; TextAreaX = 0; TextAreaY = 0; TextAreaWidth = 0; TextAreaHeight = 0; TransparencyColor = Color.Black; CommentRectangle = RectangleF.Empty; TitleRectangle = RectangleF.Empty; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Protected #region 디스플레이 시작하기 - BeginDisplay() /// <summary> /// 디스플레이 시작하기 /// </summary> public static void BeginDisplay() { if(!Instance.Visible) { Instance.SetLocation(); if(!Instance.Created) { Instance.CreateControl(); } SetWindowPos(Instance.Handle, (IntPtr)HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); Instance.Visible = true; Instance.Refresh(); } } #endregion #region 디스플레이 종료하기 - EndDisplay() /// <summary> /// 디스플레이 종료하기 /// </summary> public static void EndDisplay() { Instance.Visible = false; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Protected #region 핸들 생성시 처리하기 - OnHandleCreated(e) /// <summary> /// 핸들 생성시 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnHandleCreated(EventArgs e) { IntPtr desktopWindowHandle = IntPtr.Zero; if(Handle != IntPtr.Zero) { desktopWindowHandle = GetDesktopWindow(); SetParent(Handle, desktopWindowHandle); } if(TextAreaWidth == 0) { TextAreaWidth = ClientRectangle.Width; } if(TextAreaHeight == 0) { TextAreaHeight = ClientRectangle.Height; } CommentRectangle = new RectangleF(0, 0, (float)TextAreaWidth, (float)TextAreaHeight); TitleRectangle = new RectangleF(0, 0, (float)TextAreaWidth, (float)TextAreaHeight); base.OnHandleCreated(e); } #endregion #region 배경 이미지 변경시 처리하기 - OnBackgroundImageChanged(e) /// <summary> /// 배경 이미지 변경시 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnBackgroundImageChanged(EventArgs e) { base.OnBackgroundImageChanged(e); if(BackgroundImage != null) { Width = BackgroundImage.Width; Height = BackgroundImage.Height; SetLocation(); } Refresh(); } #endregion #region 배경 페인트시 처리하기 - OnPaintBackground(e) /// <summary> /// 배경 페인트시 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnPaintBackground(PaintEventArgs e) { } #endregion #region 페인트시 처리하기 - OnPaint(e) /// <summary> /// 페인트시 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnPaint(PaintEventArgs e) { if(Bounds.Width > 0 && Bounds.Height > 0 && Visible) { Graphics graphics = e.Graphics; graphics.SetClip(e.ClipRectangle); graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; #region 이미지 배경을 투명 처리한다. Color transparentColor = Color.FromArgb(TransparencyColor.R, TransparencyColor.G, TransparencyColor.B); IntPtr dcHandle = graphics.GetHdc(); Point point = new Point(); Color pixelColor; Bitmap bitmap = (Bitmap)BackgroundImage; BitmapHelper bitmapHelper = new BitmapHelper(bitmap); bitmapHelper.LockBitmap(); for(point.Y = 0; point.Y < BackgroundImage.Height; point.Y++) { for(point.X = 0; point.X < BackgroundImage.Width; point.X++) { if((pixelColor = bitmapHelper.GetPixel(point.X, point.Y)) != transparentColor) { SetPixel(dcHandle, point.X, point.Y, GetColorValue(pixelColor)); } } } bitmapHelper.UnlockBitmap(); graphics.ReleaseHdc(); #endregion #region 텍스트를 그린다. this.textOffsetY = TextAreaY; if(Title != string.Empty) { Font fontTitle = new Font(Font, FontStyle.Bold); SizeF titleSize = graphics.MeasureString(Title, fontTitle, TextAreaWidth, this.stringFormat); RectangleF titleRectangle = new RectangleF(TextAreaX + this.textOffsetX, this.textOffsetY, titleSize.Width, titleSize.Height); SolidBrush titleBrush = new SolidBrush(ForeColor); graphics.DrawString(Title, fontTitle, titleBrush, titleRectangle, this.stringFormat); titleBrush.Dispose(); fontTitle.Dispose(); TitleRectangle = titleRectangle; this.textOffsetY += this.leading + Convert.ToInt32(titleRectangle.Height); } if(Comment != string.Empty) { SizeF commentSize = graphics.MeasureString(Comment, CommentFont, TextAreaWidth, this.stringFormat); this.textOffsetY += Convert.ToInt32(Math.Ceiling(commentSize.Height)); RectangleF commentRectangle = new RectangleF(TextAreaX + this.textOffsetX, this.textOffsetY, commentSize.Width, commentSize.Height); SolidBrush commentBrush = new SolidBrush(ForeColor); graphics.DrawString(Comment, CommentFont, commentBrush, commentRectangle, this.stringFormat); commentBrush.Dispose(); CommentRectangle = commentRectangle; } #endregion } } #endregion #region 리소스 해제하기 - Dispose(disposing) /// <summary> /// 리소스 해제하기 /// </summary> /// <param name="disposing">해제 여부</param> protected override void Dispose(bool disposing) { if(disposing) { CommentFont.Dispose(); CommentFont = null; if(this.stringFormat != null) { this.stringFormat.Dispose(); this.stringFormat = null; } } base.Dispose(disposing); } #endregion //////////////////////////////////////////////////////////////////////////////// Private #region 배경 이미지 설정하기 - SetBackgroundImage(image) /// <summary> /// 배경 이미지 설정하기 /// </summary> /// <param name="image">이미지</param> public static void SetBackgroundImage(Image image) { Instance.BackgroundImage = image; } #endregion #region 제목 설정하기 - SetTitle(title) /// <summary> /// 제목 설정하기 /// </summary> /// <param name="title">제목</param> public static void SetTitle(string title) { Instance.Title = title; } #endregion #region 주석 설정하기 - SetComment(comment) /// <summary> /// 주석 설정하기 /// </summary> /// <param name="comment">주석</param> public static void SetComment(string comment) { Instance.Comment = comment; } #endregion #region 위치 설정하기 - SetLocation() /// <summary> /// 위치 설정하기 /// </summary> private void SetLocation() { Rectangle workingArea = SystemInformation.WorkingArea; int x = (workingArea.Width - Width ) / 2; int y = (workingArea.Height - Height) / 2; Location = new Point(x, y); } #endregion #region 색상 값 구하기 - GetColorValue(color) /// <summary> /// 색상 값 구하기 /// </summary> /// <param name="color">색상</param> /// <returns>색상 값</returns> private uint GetColorValue(Color color) { return Convert.ToUInt32((color.B << 16 | color.G << 8 | color.R)); } #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 |
using System; using System.Drawing; using System.Windows.Forms; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); TransparentSplashControl.Instance.TransparencyColor = Color.Black ; TransparentSplashControl.Instance.Width = 256; TransparentSplashControl.Instance.Height = 256; TransparentSplashControl.Instance.TextAreaX = 32; TransparentSplashControl.Instance.TextAreaY = 96; TransparentSplashControl.Instance.TextAreaWidth = 192; TransparentSplashControl.Instance.TextAreaHeight = 64; TransparentSplashControl.Instance.ForeColor = Color.White ; TransparentSplashControl.SetBackgroundImage(Image.FromFile("splash.png")); TransparentSplashControl.SetTitle("스플래시!"); this.startButton.Click += startButton_Click; this.stopButton.Click += stopButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 폼을 닫는 경우 처리하기 - OnFormClosed(e) /// <summary> /// 폼을 닫는 경우 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnFormClosed(FormClosedEventArgs e) { TransparentSplashControl.EndDisplay(); TransparentSplashControl.Instance.Dispose(); base.OnFormClosed(e); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 시작하기 버튼 클릭시 처리하기 - startButton_Click(sender, e) /// <summary> /// 시작하기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void startButton_Click(object sender, EventArgs e) { TransparentSplashControl.BeginDisplay(); } #endregion #region 중단하기 버튼 클릭시 처리하기 - stopButton_Click(sender, e) /// <summary> /// 중단하기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void stopButton_Click(object sender, EventArgs e) { TransparentSplashControl.EndDisplay(); } #endregion } } |