123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace HOZProject
- {
- /// <summary>
- /// Class UCTimeLine.
- /// Implements the <see cref="System.Windows.Forms.UserControl" />
- /// </summary>
- /// <seealso cref="System.Windows.Forms.UserControl" />
- public partial class UCTimeLine : UserControl
- {
- /// <summary>
- /// The line color
- /// </summary>
- private Color lineColor = TextColors.Light;
- /// <summary>
- /// Gets or sets the color of the line.
- /// </summary>
- /// <value>The color of the line.</value>
- [Description("连接线颜色"), Category("自定义")]
- public Color LineColor
- {
- get { return lineColor; }
- set
- {
- lineColor = value;
- Invalidate();
- }
- }
- /// <summary>
- /// The title font
- /// </summary>
- private Font titleFont = new Font("微软雅黑", 12f);
- /// <summary>
- /// Gets or sets the title font.
- /// </summary>
- /// <value>The title font.</value>
- [Description("标题字体"), Category("自定义")]
- public Font TitleFont
- {
- get { return titleFont; }
- set
- {
- titleFont = value;
- }
- }
- /// <summary>
- /// The title forcolor
- /// </summary>
- private Color titleForcolor = TextColors.Light;
- /// <summary>
- /// Gets or sets the title forcolor.
- /// </summary>
- /// <value>The title forcolor.</value>
- [Description("标题颜色"), Category("自定义")]
- public Color TitleForcolor
- {
- get { return titleForcolor; }
- set
- {
- titleForcolor = value;
- }
- }
- /// <summary>
- /// The details font
- /// </summary>
- private Font detailsFont = new Font("微软雅黑", 8);
- /// <summary>
- /// Gets or sets the details font.
- /// </summary>
- /// <value>The details font.</value>
- [Description("详情字体"), Category("自定义")]
- public Font DetailsFont
- {
- get { return detailsFont; }
- set
- {
- detailsFont = value;
- }
- }
- /// <summary>
- /// The details forcolor
- /// </summary>
- private Color detailsForcolor = TextColors.MoreDark;
- /// <summary>
- /// Gets or sets the details forcolor.
- /// </summary>
- /// <value>The details forcolor.</value>
- [Description("详情颜色"), Category("自定义")]
- public Color DetailsForcolor
- {
- get { return detailsForcolor; }
- set
- {
- detailsForcolor = value;
- }
- }
- /// <summary>
- /// The items
- /// </summary>
- public TimeLineItem[] items;
- /// <summary>
- /// Gets or sets the items.
- /// </summary>
- /// <value>The items.</value>
- [Description("项列表"), Category("自定义")]
- public TimeLineItem[] Items
- {
- get { return items; }
- set
- {
- items = value;
- }
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="UCTimeLine"/> class.
- /// </summary>
- public UCTimeLine(TimeLineItem[] tlItem,int measureType)
- {
- this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
- this.SetStyle(ControlStyles.DoubleBuffer, true);
- this.SetStyle(ControlStyles.ResizeRedraw, true);
- this.SetStyle(ControlStyles.Selectable, true);
- this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
- this.SetStyle(ControlStyles.UserPaint, true);
- InitializeComponent();
- items = tlItem;
- //加载节点信息
- ReloadItems(measureType);
- }
- /// <summary>
- /// Reloads the items.
- /// </summary>
- public void ReloadItems(int measureType)
- {
- try
- {
- ControlHelper.FreezeControl(this, true);
- this.Controls.Clear();
- if (items != null)
- {
- foreach (var item in items)
- {
- switch (measureType)
- {
- case (int)MeasureMsgManage.measureType.Photo:
- if (item.Type.ToUpper() == "PT" || item.Type.ToUpper() == "FIB")
- {
- continue;
- }
- break;
- case (int)MeasureMsgManage.measureType.FIB:
- if (item.Type.ToUpper() == "PT")
- {
- continue;
- }
- break;
- //case (int)MeasureMsgManage.measureType.PT:
- // break;
- }
- FlowLayoutPanel panelTitle = new FlowLayoutPanel();
- panelTitle.Dock = DockStyle.Top;
- panelTitle.AutoScroll = false;
- panelTitle.Padding = new System.Windows.Forms.Padding(5);
- panelTitle.Name = "Code_" + item.Code;//+ Guid.NewGuid().ToString();
- panelTitle.Tag = item.Code;
- //panelTitle.BackColor = Color.Yellow;
- Label lblTitle = new Label();
- lblTitle.Dock = DockStyle.Top;
- lblTitle.AutoSize = true;
- lblTitle.Font = titleFont;
- lblTitle.ForeColor = titleForcolor;
- lblTitle.Text = item.Title;
- lblTitle.Tag = item.Code;
- lblTitle.Name = "lbl"+item.Code;
- lblTitle.SizeChanged += item_SizeChanged;
- panelTitle.Controls.Add(lblTitle);
- this.Controls.Add(panelTitle);
- panelTitle.BringToFront();
- FlowLayoutPanel panelDetails = new FlowLayoutPanel();
- panelDetails.Dock = DockStyle.Top;
- panelDetails.AutoScroll = false;
- panelDetails.Padding = new System.Windows.Forms.Padding(5);
- panelDetails.Name = "details_" + item.Code; //"details_" + Guid.NewGuid().ToString();
- panelDetails.BackColor = Color.White;
- Label lblDetails = new Label();
- lblDetails.AutoSize = true;
- lblDetails.Dock = DockStyle.Top;
- lblDetails.Font = detailsFont;
- lblDetails.ForeColor = detailsForcolor;
- lblDetails.Text = item.Details;
- lblDetails.SizeChanged += item_SizeChanged;
- panelDetails.Controls.Add(lblDetails);
- this.Controls.Add(panelDetails);
- panelDetails.BringToFront();
- }
- }
- }
- finally
- {
- ControlHelper.FreezeControl(this, false);
- }
- }
- /// <summary>
- /// Handles the SizeChanged event of the item control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- void item_SizeChanged(object sender, EventArgs e)
- {
- Label lbl = (Label)sender;
- lbl.Parent.Height = lbl.Height + 10;
- }
- /// <summary>
- /// 引发 <see cref="E:System.Windows.Forms.Control.Paint" /> 事件。
- /// </summary>
- /// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.PaintEventArgs" />。</param>
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- var g = e.Graphics;
- g.SetGDIHigh();
- var lst = this.Controls.ToArray().Where(p => p.Name.StartsWith("Code_")).ToList();
- //for (int i = lst.Count-1;i>=0; i--)
- for (int i = 0; i<lst.Count; i++)
- {
- Label label = (Label)lst[i].Controls[0];
- foreach (var item in items)
- {
- if(label.Tag.ToString() == item.Code)
- {
- #region State Int 判断方法
- switch (item.State)
- {
- //出错
- case 0:
- lineColor = Color.Red;
- break;
- //完成
- case 1:
- lineColor = Color.Blue;
- break;
- default:
- lineColor = TextColors.Light;
- break;
- }
- #endregion
- //if (item.State)
- //{
- // lineColor = Color.GreenYellow;
- //}
- //else
- //{
- // lineColor = Color.Red;
- //}
- break;
- }
- }
- //画圆
- g.DrawEllipse(new Pen(new SolidBrush(lineColor)), new Rectangle(7, lst[i].Location.Y + 10, 16, 16));
- //划线
- if (i != lst.Count - 1)
- {
- 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));
- }
- }
- }
- }
- /// <summary>
- /// Class TimeLineItem.
- /// </summary>
- public class TimeLineItem
- {
- /// <summary>
- /// Gets or sets the title.
- /// </summary>
- /// <value>The title.</value>
- public string Title { get; set; }
- /// <summary>
- /// Gets or sets the details.
- /// </summary>
- /// <value>The details.</value>
- public string Details { get; set; }
- /// <summary>
- /// Gets or sets the Code.
- /// </summary>
- /// <value>The Code.</value>
- public string Code { get; set; }
- /// <summary>
- /// Gets or sets the State.
- /// </summary>
- /// <value>The State.</value>
- public int State { get; set; }
- /// <summary>
- /// Gets or sets the IsData.
- /// </summary>
- /// <value>The IsData.</value>
- public bool IsData { get; set; }
- /// <summary>
- /// Gets or sets the Type.
- /// </summary>
- /// <value>The Type.</value>
- public string Type { get; set; }
- /// <summary>
- /// Gets or sets the Show.
- /// </summary>
- /// <value>The Show.</value>
- public bool IsShow { get; set; }
- /// <summary>
- /// Gets or sets the Index.
- /// </summary>
- /// <value>The Index.</value>
- public int Index { get; set; }
- }
- }
|