UCTimeLine.cs 13 KB

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