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
{
///
/// 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("微软雅黑", 12f);
///
/// 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("微软雅黑", 8);
///
/// 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);
}
///
/// Reloads the items.
///
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);
}
}
///
/// 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);
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
/// 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; }
}
}