UCTimeLine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 HOZProject
  10. {
  11. /// <summary>
  12. /// Class UCTimeLine.
  13. /// Implements the <see cref="System.Windows.Forms.UserControl" />
  14. /// </summary>
  15. /// <seealso cref="System.Windows.Forms.UserControl" />
  16. public partial class UCTimeLine : UserControl
  17. {
  18. /// <summary>
  19. /// The line color
  20. /// </summary>
  21. private Color lineColor = TextColors.Light;
  22. /// <summary>
  23. /// Gets or sets the color of the line.
  24. /// </summary>
  25. /// <value>The color of the line.</value>
  26. [Description("连接线颜色"), Category("自定义")]
  27. public Color LineColor
  28. {
  29. get { return lineColor; }
  30. set
  31. {
  32. lineColor = value;
  33. Invalidate();
  34. }
  35. }
  36. /// <summary>
  37. /// The title font
  38. /// </summary>
  39. private Font titleFont = new Font("微软雅黑", 12f);
  40. /// <summary>
  41. /// Gets or sets the title font.
  42. /// </summary>
  43. /// <value>The title font.</value>
  44. [Description("标题字体"), Category("自定义")]
  45. public Font TitleFont
  46. {
  47. get { return titleFont; }
  48. set
  49. {
  50. titleFont = value;
  51. }
  52. }
  53. /// <summary>
  54. /// The title forcolor
  55. /// </summary>
  56. private Color titleForcolor = TextColors.Light;
  57. /// <summary>
  58. /// Gets or sets the title forcolor.
  59. /// </summary>
  60. /// <value>The title forcolor.</value>
  61. [Description("标题颜色"), Category("自定义")]
  62. public Color TitleForcolor
  63. {
  64. get { return titleForcolor; }
  65. set
  66. {
  67. titleForcolor = value;
  68. }
  69. }
  70. /// <summary>
  71. /// The details font
  72. /// </summary>
  73. private Font detailsFont = new Font("微软雅黑", 8);
  74. /// <summary>
  75. /// Gets or sets the details font.
  76. /// </summary>
  77. /// <value>The details font.</value>
  78. [Description("详情字体"), Category("自定义")]
  79. public Font DetailsFont
  80. {
  81. get { return detailsFont; }
  82. set
  83. {
  84. detailsFont = value;
  85. }
  86. }
  87. /// <summary>
  88. /// The details forcolor
  89. /// </summary>
  90. private Color detailsForcolor = TextColors.MoreDark;
  91. /// <summary>
  92. /// Gets or sets the details forcolor.
  93. /// </summary>
  94. /// <value>The details forcolor.</value>
  95. [Description("详情颜色"), Category("自定义")]
  96. public Color DetailsForcolor
  97. {
  98. get { return detailsForcolor; }
  99. set
  100. {
  101. detailsForcolor = value;
  102. }
  103. }
  104. /// <summary>
  105. /// The items
  106. /// </summary>
  107. public TimeLineItem[] items;
  108. /// <summary>
  109. /// Gets or sets the items.
  110. /// </summary>
  111. /// <value>The items.</value>
  112. [Description("项列表"), Category("自定义")]
  113. public TimeLineItem[] Items
  114. {
  115. get { return items; }
  116. set
  117. {
  118. items = value;
  119. }
  120. }
  121. /// <summary>
  122. /// Initializes a new instance of the <see cref="UCTimeLine"/> class.
  123. /// </summary>
  124. public UCTimeLine(TimeLineItem[] tlItem,int measureType)
  125. {
  126. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  127. this.SetStyle(ControlStyles.DoubleBuffer, true);
  128. this.SetStyle(ControlStyles.ResizeRedraw, true);
  129. this.SetStyle(ControlStyles.Selectable, true);
  130. this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  131. this.SetStyle(ControlStyles.UserPaint, true);
  132. InitializeComponent();
  133. items = tlItem;
  134. //加载节点信息
  135. ReloadItems(measureType);
  136. }
  137. /// <summary>
  138. /// Reloads the items.
  139. /// </summary>
  140. public void ReloadItems(int measureType)
  141. {
  142. try
  143. {
  144. ControlHelper.FreezeControl(this, true);
  145. this.Controls.Clear();
  146. if (items != null)
  147. {
  148. foreach (var item in items)
  149. {
  150. switch (measureType)
  151. {
  152. case (int)MeasureMsgManage.measureType.Photo:
  153. if (item.Type.ToUpper() == "PT" || item.Type.ToUpper() == "FIB")
  154. {
  155. continue;
  156. }
  157. break;
  158. case (int)MeasureMsgManage.measureType.FIB:
  159. if (item.Type.ToUpper() == "PT")
  160. {
  161. continue;
  162. }
  163. break;
  164. //case (int)MeasureMsgManage.measureType.PT:
  165. // break;
  166. }
  167. FlowLayoutPanel panelTitle = new FlowLayoutPanel();
  168. panelTitle.Dock = DockStyle.Top;
  169. panelTitle.AutoScroll = false;
  170. panelTitle.Padding = new System.Windows.Forms.Padding(5);
  171. panelTitle.Name = "Code_" + item.Code;//+ Guid.NewGuid().ToString();
  172. panelTitle.Tag = item.Code;
  173. //panelTitle.BackColor = Color.Yellow;
  174. Label lblTitle = new Label();
  175. lblTitle.Dock = DockStyle.Top;
  176. lblTitle.AutoSize = true;
  177. lblTitle.Font = titleFont;
  178. lblTitle.ForeColor = titleForcolor;
  179. lblTitle.Text = item.Title;
  180. lblTitle.Tag = item.Code;
  181. lblTitle.Name = "lbl"+item.Code;
  182. lblTitle.SizeChanged += item_SizeChanged;
  183. panelTitle.Controls.Add(lblTitle);
  184. this.Controls.Add(panelTitle);
  185. panelTitle.BringToFront();
  186. FlowLayoutPanel panelDetails = new FlowLayoutPanel();
  187. panelDetails.Dock = DockStyle.Top;
  188. panelDetails.AutoScroll = false;
  189. panelDetails.Padding = new System.Windows.Forms.Padding(5);
  190. panelDetails.Name = "details_" + item.Code; //"details_" + Guid.NewGuid().ToString();
  191. panelDetails.BackColor = Color.White;
  192. Label lblDetails = new Label();
  193. lblDetails.AutoSize = true;
  194. lblDetails.Dock = DockStyle.Top;
  195. lblDetails.Font = detailsFont;
  196. lblDetails.ForeColor = detailsForcolor;
  197. lblDetails.Text = item.Details;
  198. lblDetails.SizeChanged += item_SizeChanged;
  199. panelDetails.Controls.Add(lblDetails);
  200. this.Controls.Add(panelDetails);
  201. panelDetails.BringToFront();
  202. }
  203. }
  204. }
  205. finally
  206. {
  207. ControlHelper.FreezeControl(this, false);
  208. }
  209. }
  210. /// <summary>
  211. /// Handles the SizeChanged event of the item control.
  212. /// </summary>
  213. /// <param name="sender">The source of the event.</param>
  214. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  215. void item_SizeChanged(object sender, EventArgs e)
  216. {
  217. Label lbl = (Label)sender;
  218. lbl.Parent.Height = lbl.Height + 10;
  219. }
  220. /// <summary>
  221. /// 引发 <see cref="E:System.Windows.Forms.Control.Paint" /> 事件。
  222. /// </summary>
  223. /// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.PaintEventArgs" />。</param>
  224. protected override void OnPaint(PaintEventArgs e)
  225. {
  226. base.OnPaint(e);
  227. var g = e.Graphics;
  228. g.SetGDIHigh();
  229. var lst = this.Controls.ToArray().Where(p => p.Name.StartsWith("Code_")).ToList();
  230. //for (int i = lst.Count-1;i>=0; i--)
  231. for (int i = 0; i<lst.Count; i++)
  232. {
  233. Label label = (Label)lst[i].Controls[0];
  234. foreach (var item in items)
  235. {
  236. if(label.Tag.ToString() == item.Code)
  237. {
  238. #region State Int 判断方法
  239. switch (item.State)
  240. {
  241. //出错
  242. case 0:
  243. lineColor = Color.Red;
  244. break;
  245. //完成
  246. case 1:
  247. lineColor = Color.Blue;
  248. break;
  249. default:
  250. lineColor = TextColors.Light;
  251. break;
  252. }
  253. #endregion
  254. //if (item.State)
  255. //{
  256. // lineColor = Color.GreenYellow;
  257. //}
  258. //else
  259. //{
  260. // lineColor = Color.Red;
  261. //}
  262. break;
  263. }
  264. }
  265. //画圆
  266. g.DrawEllipse(new Pen(new SolidBrush(lineColor)), new Rectangle(7, lst[i].Location.Y + 10, 16, 16));
  267. //划线
  268. if (i != lst.Count - 1)
  269. {
  270. g.DrawLine(new Pen(new SolidBrush(lineColor)), new Point(7 + 8, lst[i].Location.Y + 10 - 2), new Point(7 + 8, lst[i + 1].Location.Y + 10 + 16 + 2));
  271. }
  272. }
  273. }
  274. }
  275. /// <summary>
  276. /// Class TimeLineItem.
  277. /// </summary>
  278. public class TimeLineItem
  279. {
  280. /// <summary>
  281. /// Gets or sets the title.
  282. /// </summary>
  283. /// <value>The title.</value>
  284. public string Title { get; set; }
  285. /// <summary>
  286. /// Gets or sets the details.
  287. /// </summary>
  288. /// <value>The details.</value>
  289. public string Details { get; set; }
  290. /// <summary>
  291. /// Gets or sets the Code.
  292. /// </summary>
  293. /// <value>The Code.</value>
  294. public string Code { get; set; }
  295. /// <summary>
  296. /// Gets or sets the State.
  297. /// </summary>
  298. /// <value>The State.</value>
  299. public int State { get; set; }
  300. /// <summary>
  301. /// Gets or sets the IsData.
  302. /// </summary>
  303. /// <value>The IsData.</value>
  304. public bool IsData { get; set; }
  305. /// <summary>
  306. /// Gets or sets the Type.
  307. /// </summary>
  308. /// <value>The Type.</value>
  309. public string Type { get; set; }
  310. /// <summary>
  311. /// Gets or sets the Show.
  312. /// </summary>
  313. /// <value>The Show.</value>
  314. public bool IsShow { get; set; }
  315. /// <summary>
  316. /// Gets or sets the Index.
  317. /// </summary>
  318. /// <value>The Index.</value>
  319. public int Index { get; set; }
  320. }
  321. }