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 { /// /// Class UCTimeLine. /// Implements the /// /// public partial class UCTimeLine : UserControl { /// /// Timed flashing /// /// /// The line color /// private Color lineColor = TextColors.Light; /// /// Gets or sets the color of the line. /// /// The color of the line. [Description("连接线颜色"), Category("自定义")] public Color LineColor { get { return lineColor; } set { lineColor = value; Invalidate(); } } /// /// The title font /// private Font titleFont = new Font("微软雅黑", 11f); /// /// Gets or sets the title font. /// /// The title font. [Description("标题字体"), Category("自定义")] public Font TitleFont { get { return titleFont; } set { titleFont = value; } } /// /// The title forcolor /// private Color titleForcolor = TextColors.Light; /// /// Gets or sets the title forcolor. /// /// The title forcolor. [Description("标题颜色"), Category("自定义")] public Color TitleForcolor { get { return titleForcolor; } set { titleForcolor = value; } } /// /// The details font /// private Font detailsFont = new Font("微软雅黑", 12); /// /// Gets or sets the details font. /// /// The details font. [Description("详情字体"), Category("自定义")] public Font DetailsFont { get { return detailsFont; } set { detailsFont = value; } } /// /// The details forcolor /// private Color detailsForcolor = TextColors.MoreDark; /// /// Gets or sets the details forcolor. /// /// The details forcolor. [Description("详情颜色"), Category("自定义")] public Color DetailsForcolor { get { return detailsForcolor; } set { detailsForcolor = value; } } /// /// The items /// public TimeLineItem[] items; /// /// Gets or sets the items. /// /// The items. [Description("项列表"), Category("自定义")] public TimeLineItem[] Items { get { return items; } set { items = value; } } /// /// Initializes a new instance of the class. /// 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); twinkleItem = items[0];//默认是启动后,在第一个条目上闪烁 } /// /// Reloads the items. /// public void ReloadItems(int measureType) { try { ControlHelper.FreezeControl(this, true); this.Controls.Clear(); if (items != null) { foreach (var item in items) { 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(); item.codeLabel = panelTitle; 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 = titleForcolor; lblDetails.Text = item.Details; lblDetails.SizeChanged += item_SizeChanged; panelDetails.Controls.Add(lblDetails); this.Controls.Add(panelDetails); panelDetails.BringToFront(); item.detailLabel = panelDetails; } } } finally { ControlHelper.FreezeControl(this, false); } } /// /// Handles the SizeChanged event of the item control. /// /// The source of the event. /// The instance containing the event data. void item_SizeChanged(object sender, EventArgs e) { Label lbl = (Label)sender; lbl.Parent.Height = lbl.Height + 10; } /// /// 引发 事件。 /// /// 包含事件数据的 。 protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); DoAnimation(e.Graphics); Dotwinkle(e.Graphics); } public void DoAnimation(Graphics myGraphic) { var g = myGraphic; g.SetGDIHigh(); var itemlist = items.ToList(); for (int i = 0; i < itemlist.Count; i++) { var codelabel = itemlist[i].codeLabel; var labeText = itemlist[i].detailLabel; var item = itemlist[i]; switch (item.State) { //出错 case 0: lineColor = Color.Red; //空心 g.DrawEllipse(new Pen(new SolidBrush(Color.Red)), new Rectangle(7, codelabel.Location.Y + 10, 16, 16)); //画实心圆 g.FillEllipse(new SolidBrush(Color.Red), new Rectangle(7 + 5, codelabel.Location.Y + 16, 5, 5)); codelabel.Controls[0].ForeColor = Color.Red; labeText.Controls[0].ForeColor = Color.Red; FormHOZMain.ControlFlicker = false; break; //完成 case 1: //lineColor = Color.Lime; //画实心圆 g.FillEllipse(new SolidBrush(Color.Lime), new Rectangle(7 + 5, codelabel.Location.Y + 16, 5, 5)); //空心 g.DrawEllipse(new Pen(new SolidBrush(Color.Lime)), new Rectangle(7, codelabel.Location.Y + 10, 16, 16)); codelabel.Controls[0].ForeColor = TextColors.Light; labeText.Controls[0].ForeColor = TextColors.Light; break; default: lineColor = TextColors.Light; g.DrawEllipse(new Pen(new SolidBrush(lineColor)), new Rectangle(7, codelabel.Location.Y + 10, 16, 16)); g.FillEllipse(new SolidBrush(lineColor), new Rectangle(7 + 5, codelabel.Location.Y + 16, 5, 5)); break; } //划线 if (i != itemlist.Count - 1) { 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 } } } private void UCTimeLine_Paint(object sender, PaintEventArgs e) { } public TimeLineItem twinkleItem; private static bool twincleSwitch=false; public void Dotwinkle(Graphics g) { FlowLayoutPanel panel = twinkleItem.codeLabel; if (twincleSwitch ==false) { twincleSwitch = true; } else { twincleSwitch = false; } if (twincleSwitch == false) { //画空心圆 g.DrawEllipse(new Pen(new SolidBrush(Color.DarkOrange)), new Rectangle(7, panel.Location.Y + 10, 16, 16)); //画实心圆 g.FillEllipse(new SolidBrush(Color.DarkOrange), new Rectangle(7 + 5, panel.Location.Y + 16, 5, 5)); Label label =(Label) panel.Controls[0]; label.ForeColor = Color.DarkOrange; } else { //画空心圆 g.DrawEllipse(new Pen(new SolidBrush(lineColor)), new Rectangle(7, panel.Location.Y + 10, 16, 16)); //画实心圆 g.FillEllipse(new SolidBrush(lineColor), new Rectangle(7 + 5, panel.Location.Y + 16, 5, 5)); Label label = (Label)panel.Controls[0]; label.ForeColor = TextColors.Light; } } } /// /// Class TimeLineItem. /// public class TimeLineItem { /// /// Gets or sets the title. /// /// The title. public string Title { get; set; } /// /// Gets or sets the details. /// /// The details. public string Details { get; set; } /// /// Gets or sets the Code. /// /// The Code. public string Code { get; set; } /// /// Gets or sets the State. /// /// The State. public int State { get; set; } /// /// Gets or sets the IsData. /// /// The IsData. public bool IsData { get; set; } /// /// Gets or sets the Type. /// /// The Type. public string Type { get; set; } /// /// Gets or sets the Show. /// /// The Show. public bool IsShow { get; set; } /// /// Gets or sets the Index. /// /// The Index. public int Index { get; set; } public FlowLayoutPanel codeLabel { get; set; } public FlowLayoutPanel detailLabel { get; set; } } }