MindMappingItemEntity.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 2019-09-11
  4. //
  5. // ***********************************************************************
  6. // <copyright file="MindMappingItemEntity.cs">
  7. // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
  8. // </copyright>
  9. //
  10. // Blog: https://www.cnblogs.com/bfyx
  11. // GitHub:https://github.com/kwwwvagaa/NetWinformControl
  12. // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
  13. //
  14. // If you use this code, please keep this note.
  15. // ***********************************************************************
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Drawing;
  21. namespace HZH_Controls.Controls
  22. {
  23. /// <summary>
  24. /// Class MindMappingItemEntity.
  25. /// </summary>
  26. public class MindMappingItemEntity
  27. {
  28. /// <summary>
  29. /// Gets or sets the identifier.
  30. /// </summary>
  31. /// <value>The identifier.</value>
  32. public string ID { get; set; }
  33. /// <summary>
  34. /// The text
  35. /// </summary>
  36. private string _text;
  37. /// <summary>
  38. /// Gets or sets the text.
  39. /// </summary>
  40. /// <value>The text.</value>
  41. public string Text
  42. {
  43. get { return _text; }
  44. set
  45. {
  46. _text = value;
  47. ResetSize();
  48. }
  49. }
  50. /// <summary>
  51. /// Gets or sets the data source.
  52. /// </summary>
  53. /// <value>The data source.</value>
  54. public object DataSource { get; set; }
  55. /// <summary>
  56. /// The childrens
  57. /// </summary>
  58. private MindMappingItemEntity[] _Childrens;
  59. /// <summary>
  60. /// Gets or sets the childrens.
  61. /// </summary>
  62. /// <value>The childrens.</value>
  63. public MindMappingItemEntity[] Childrens
  64. {
  65. get { return _Childrens; }
  66. set
  67. {
  68. _Childrens = value;
  69. if (value != null && value.Length > 0)
  70. {
  71. value.ToList().ForEach(p => { if (p != null) { p.ParentItem = this; } });
  72. }
  73. }
  74. }
  75. /// <summary>
  76. /// The back color
  77. /// </summary>
  78. private Color? backColor;
  79. /// <summary>
  80. /// Gets or sets the color of the back.
  81. /// </summary>
  82. /// <value>The color of the back.</value>
  83. public Color? BackColor
  84. {
  85. get { return backColor; }
  86. set { backColor = value; }
  87. }
  88. /// <summary>
  89. /// The font
  90. /// </summary>
  91. private Font font = new Font("微软雅黑", 10);
  92. /// <summary>
  93. /// Gets or sets the font.
  94. /// </summary>
  95. /// <value>The font.</value>
  96. public Font Font
  97. {
  98. get { return font; }
  99. set
  100. {
  101. font = value;
  102. ResetSize();
  103. }
  104. }
  105. /// <summary>
  106. /// The fore color
  107. /// </summary>
  108. private Color foreColor = Color.Black;
  109. /// <summary>
  110. /// Gets or sets the color of the fore.
  111. /// </summary>
  112. /// <value>The color of the fore.</value>
  113. public Color ForeColor
  114. {
  115. get { return foreColor; }
  116. set { foreColor = value; }
  117. }
  118. /// <summary>
  119. /// The is expansion
  120. /// </summary>
  121. private bool _IsExpansion = false;
  122. /// <summary>
  123. /// Gets or sets a value indicating whether the instance is expanded.
  124. /// </summary>
  125. /// <value><c>true</c> if this instance is expansion; otherwise, <c>false</c>.</value>
  126. public bool IsExpansion
  127. {
  128. get
  129. {
  130. return _IsExpansion;
  131. }
  132. set
  133. {
  134. if (value == _IsExpansion)
  135. return;
  136. _IsExpansion = value;
  137. if (!value && _Childrens != null && _Childrens.Length > 0)
  138. {
  139. _Childrens.ToList().ForEach(p => { if (p != null) { p.IsExpansion = false; } });
  140. }
  141. }
  142. }
  143. /// <summary>
  144. /// Gets the parent item.
  145. /// </summary>
  146. /// <value>The parent item.</value>
  147. public MindMappingItemEntity ParentItem { get; private set; }
  148. /// <summary>
  149. /// Gets all childrens maximum show count.
  150. /// </summary>
  151. /// <value>All childrens maximum show count.</value>
  152. public int AllChildrensMaxShowHeight { get { return GetAllChildrensMaxShowHeight(); } }
  153. /// <summary>
  154. /// Gets the maximum level.
  155. /// </summary>
  156. /// <value>The maximum level.</value>
  157. public int AllChildrensMaxShowWidth { get { return GetAllChildrensMaxShowWidth(); } }
  158. /// <summary>
  159. /// Gets all childrens maximum show count.
  160. /// </summary>
  161. /// <returns>System.Int32.</returns>
  162. private int GetAllChildrensMaxShowHeight()
  163. {
  164. if (!_IsExpansion || _Childrens == null || _Childrens.Length <= 0)
  165. return ItemHeight + 10;
  166. else
  167. {
  168. return _Childrens.Sum(p => p == null ? 0 : p.AllChildrensMaxShowHeight);
  169. }
  170. }
  171. /// <summary>
  172. /// Gets the maximum level.
  173. /// </summary>
  174. /// <returns>System.Int32.</returns>
  175. private int GetAllChildrensMaxShowWidth()
  176. {
  177. if (!_IsExpansion || _Childrens == null || _Childrens.Length <= 0)
  178. return ItemWidth + 50;
  179. else
  180. {
  181. return ItemWidth + 50 + _Childrens.Max(p => p == null ? 0 : p.AllChildrensMaxShowWidth);
  182. }
  183. }
  184. /// <summary>
  185. /// Gets or sets the working rectangle.
  186. /// </summary>
  187. /// <value>The working rectangle.</value>
  188. internal RectangleF WorkingRectangle { get; set; }
  189. /// <summary>
  190. /// Gets or sets the draw rectangle.
  191. /// </summary>
  192. /// <value>The draw rectangle.</value>
  193. internal RectangleF DrawRectangle { get; set; }
  194. /// <summary>
  195. /// Gets or sets the expansion rectangle.
  196. /// </summary>
  197. /// <value>The expansion rectangle.</value>
  198. internal RectangleF ExpansionRectangle { get; set; }
  199. /// <summary>
  200. /// Gets the height of the item.
  201. /// </summary>
  202. /// <value>The height of the item.</value>
  203. int ItemHeight { get; set; }
  204. /// <summary>
  205. /// Gets the width of the item.
  206. /// </summary>
  207. /// <value>The width of the item.</value>
  208. int ItemWidth { get; set; }
  209. /// <summary>
  210. /// Resets the size.
  211. /// </summary>
  212. private void ResetSize()
  213. {
  214. string _t = _text;
  215. if (string.IsNullOrEmpty(_t))
  216. {
  217. _t = "aaaa";
  218. }
  219. Bitmap bit = new Bitmap(1, 1);
  220. var g = Graphics.FromImage(bit);
  221. var size = g.MeasureString(_t, font);
  222. g.Dispose();
  223. bit.Dispose();
  224. ItemHeight = (int)size.Height;
  225. ItemWidth = (int)size.Width;
  226. }
  227. }
  228. }