ThumbnailCtrl.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.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. /// <summary>
  68. /// 썸네일 이미지 클릭 이벤트
  69. /// </summary>
  70. /// <param name="sender">The source of the event.</param>
  71. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  72. private void Pic_Click(object sender, EventArgs e)
  73. {
  74. PictureBox picBox = sender as PictureBox;
  75. if (picBox == null)
  76. {
  77. return;
  78. }
  79. if (picBox.Tag == null)
  80. {
  81. return;
  82. }
  83. int index = (int)picBox.Tag;
  84. if (SelectImageChanged != null)
  85. {
  86. EventArgs eventArgs = new EventArgs();
  87. SelectImageChanged.Invoke(index);
  88. }
  89. }
  90. public delegate void IndexChangeHandler(int index);
  91. public event IndexChangeHandler SelectImageChanged = null;
  92. public int currentImageIndex = 0;
  93. internal void SetCurrentImageIndex(int currentImageIndex)
  94. {
  95. this.currentImageIndex = currentImageIndex;
  96. this.Invalidate();
  97. }
  98. private bool IsInDesignMode
  99. {
  100. get
  101. {
  102. return DesignMode || LicenseManager.UsageMode == LicenseUsageMode.Designtime;
  103. }
  104. }
  105. protected override void OnPaint(PaintEventArgs e)
  106. {
  107. base.OnPaint(e);
  108. if(IsInDesignMode)
  109. {
  110. return;
  111. }
  112. if (pics.Count < 1)
  113. {
  114. return;
  115. }
  116. using (Pen pen = new Pen(Color.Blue, 2.0f))
  117. {
  118. Rectangle rect = new Rectangle(pics[this.currentImageIndex].Location, pics[this.currentImageIndex].Size);
  119. rect.Inflate(2, 2);
  120. e.Graphics.DrawRectangle(pen, rect);
  121. }
  122. }
  123. }
  124. }