ThumbnailCtrl.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace CLIP.eForm.Consent.Dfh.UI
  10. {
  11. /// <summary>
  12. /// 이미지 뷰어 관련 컨트롤 클래스
  13. /// </summary>
  14. /// <remarks>
  15. /// <p>[설계자]</p>
  16. /// <p> 클립소프트 연구소 홍지철 (jchong@clipsoft.co.kr)</p>
  17. /// <p>[원본 작성자]</p>
  18. /// <p> 클립소프트 연구소 홍지철 (jchong@clipsoft.co.kr)</p>
  19. /// <p>[수정 작성자]</p>
  20. /// <p> </p>
  21. /// <p>----------------------------------------------------------------------------------------</p>
  22. /// <p>[HISTORY]</p>
  23. /// <p> 2016-07-01 : 최초작성</p>
  24. /// <p>----------------------------------------------------------------------------------------</p>
  25. /// </remarks>
  26. public partial class ThumbnailCtrl : UserControl
  27. {
  28. public ThumbnailCtrl()
  29. {
  30. InitializeComponent();
  31. }
  32. Dictionary<int,PictureBox> pics = new Dictionary<int,PictureBox>();
  33. public void UpdateThumbnailImages(List<Image> images)
  34. {
  35. this.currentImageIndex = 0;
  36. pics.Clear();
  37. List<Control> removeTarget = new List<Control>();
  38. foreach (Control ctrl in this.Controls)
  39. {
  40. if (ctrl is PictureBox)
  41. {
  42. removeTarget.Add(ctrl);
  43. }
  44. }
  45. this.Controls.Clear();
  46. foreach (Control ctrl in removeTarget)
  47. {
  48. ctrl.Dispose();
  49. }
  50. this.Size = new Size(50 * images.Count + 20 * images.Count + 5, 80);
  51. int index = 0;
  52. foreach (Image img in images)
  53. {
  54. PictureBox pic = new PictureBox();
  55. pic.Size = new Size(50, 70);
  56. pic.Location = new Point(index * 70 + 3, 3);
  57. pic.SizeMode = PictureBoxSizeMode.StretchImage;
  58. this.Controls.Add(pic);
  59. pics.Add(index, pic);
  60. pic.Image = img;
  61. pic.Tag = index;
  62. pic.Click += Pic_Click;
  63. index++;
  64. }
  65. this.Invalidate();
  66. }
  67. private void Pic_Click(object sender, EventArgs e)
  68. {
  69. PictureBox picBox = sender as PictureBox;
  70. if (picBox == null)
  71. {
  72. return;
  73. }
  74. if (picBox.Tag == null)
  75. {
  76. return;
  77. }
  78. int index = (int)picBox.Tag;
  79. if (SelectImageChanged != null)
  80. {
  81. EventArgs eventArgs = new EventArgs();
  82. SelectImageChanged.Invoke(index);
  83. }
  84. }
  85. public delegate void IndexChangeHandler(int index);
  86. public event IndexChangeHandler SelectImageChanged = null;
  87. public int currentImageIndex = 0;
  88. internal void SetCurrentImageIndex(int currentImageIndex)
  89. {
  90. this.currentImageIndex = currentImageIndex;
  91. this.Invalidate();
  92. }
  93. private bool IsInDesignMode
  94. {
  95. get
  96. {
  97. return DesignMode || LicenseManager.UsageMode == LicenseUsageMode.Designtime;
  98. }
  99. }
  100. protected override void OnPaint(PaintEventArgs e)
  101. {
  102. base.OnPaint(e);
  103. if(IsInDesignMode)
  104. {
  105. return;
  106. }
  107. if (pics.Count < 1)
  108. {
  109. return;
  110. }
  111. using (Pen pen = new Pen(Color.Blue, 2.0f))
  112. {
  113. Rectangle rect = new Rectangle(pics[this.currentImageIndex].Location, pics[this.currentImageIndex].Size);
  114. rect.Inflate(2, 2);
  115. e.Graphics.DrawRectangle(pen, rect);
  116. }
  117. }
  118. }
  119. }