/// <summary>
/// 绘制 MonthItem 元素,包括下面的 DateItem 和 DateTimeItem 子元素
/// </summary>
/// <param name="g"></param>
/// <param name="index"></param>
/// <param name="item"></param>
private void DrawTimelineItem(Graphics g, int index, MonthItem item)
{
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
// margin
Rectangle bound = item.Bound;
//g.DrawRectangle(new Pen(SystemColors.ControlDark), bound);
g.DrawLine(new Pen(SystemColors.ControlLight) { DashStyle = System.Drawing.Drawing2D.DashStyle.Dot }, 5, bound.Top + 23, bound.Width - 10, bound.Top + 23);
Point start = new Point(5 + 18, bound.Top + (index > 0 ? 0 : 5));
Point end = new Point(5 + 18, bound.Bottom - (index < this.DataList.Count - 1 ? 0 : 5));
g.DrawLine(new Pen(SystemColors.ControlLight), start, end);
Rectangle iconRect = new Rectangle(5, bound.Top + 5, 36, 36);
g.FillEllipse(Brushes.Orange, iconRect);
g.DrawString(item.DateLabel, this.Font, Brushes.White, iconRect, sf);
if (item.List != null)
{
StringFormat subSf = new StringFormat();
subSf.LineAlignment = StringAlignment.Center;
Font subTitleFont = new Font("仿宋", 12, FontStyle.Bold | FontStyle.Italic) { };
int top = bound.Top + 15;
for (int i = 0; i < item.List.Count; i++)
{
top = top + 32;
DateItem subItem = item.List[i];
Rectangle subIconRect = new Rectangle(5 + 12, top + 9, 12, 12);
g.FillEllipse(Brushes.Orange, subIconRect);
//g.DrawEllipse(new Pen(Color.Orange) { Width=2.0f }, subIconRect);
//g.DrawString((i + 1).ToString(), this.Font, Brushes.White, subIconRect, sf);
subIconRect.Inflate(-2, -2);
g.FillEllipse(Brushes.White, subIconRect);
Rectangle subRect = new Rectangle(56, top, bound.Width - 64, 32);
if (subItem.Selected)
{
using (var roundedRectanglePath = CreateRoundedRectanglePath(subRect, 2))
{
g.FillPath(new SolidBrush(Color.FromArgb(240, 245, 249)), roundedRectanglePath);
}
}
Rectangle subTitleRect = new Rectangle(56, top, bound.Width - 64 - 30, 32);
//g.DrawRectangle(new Pen(Color.Orange), subTitleRect);
//g.DrawString((i + 1) + "、" + subItem.Title, this.Font, Brushes.Red, subTitleRect, subSf);
Brush subTitleBrush = Brushes.Black;
g.DrawString(subItem.Date.ToString("yyyy-MM-dd"), subTitleFont, subTitleBrush, subTitleRect, subSf);
//g.FillRectangle(Brushes.Red, subTitleRect);
Rectangle subOptionRect = new Rectangle(bound.X + bound.Width - 34 + 4, top + 8, 16, 16);
//g.FillRectangle(Brushes.Yellow, subOptionRect);
g.DrawImage(this.TimeLineIcons.Images[2], subOptionRect);
subItem.AddRect = subOptionRect;
subItem.ClickRect = subRect;
if (subItem.List != null)
{
for (int j = 0; j < subItem.List.Count; j++)
{
top = top + 32;
DateTimeItem subsubItem = subItem.List[j];
//Rectangle subsubIconRect = new Rectangle(5 + 14, top + 10, 8, 8);
//g.FillEllipse(Brushes.Orange, subsubIconRect);
//subsubIconRect.Inflate(-2, -2);
//g.FillEllipse(Brushes.White, subsubIconRect);
Rectangle DateTimeItemClickRect = new Rectangle(56, top + 2, bound.Width - 64, 28);
if (!string.IsNullOrEmpty(subsubItem.Summary))
DateTimeItemClickRect = new Rectangle(DateTimeItemClickRect.X, DateTimeItemClickRect.Y, DateTimeItemClickRect.Width, DateTimeItemClickRect.Height + 32);
if (subsubItem.Selected)
{
using (var roundedRectanglePath = CreateRoundedRectanglePath(DateTimeItemClickRect, 2))
{
g.FillPath(new SolidBrush(Color.FromArgb(240, 245, 249)), roundedRectanglePath);
}
}
Brush drawTitleBrush = Brushes.Black;
if (subsubItem.Selected)
drawTitleBrush = Brushes.Blue;
Color drawTitleColor = Color.Black;
if (subsubItem.Selected)
drawTitleColor = Color.Blue;
if (!subsubItem.Selected)
{
switch (subsubItem.Level)
{
case ImportantLevel.Important:
drawTitleColor = Color.Orange;
break;
case ImportantLevel.MoreImportant:
drawTitleColor = Color.Brown;
break;
case ImportantLevel.MostImportant:
drawTitleColor = Color.Red;
break;
}
}
//Rectangle subsubImgRect = new Rectangle(56 + 0, top + 7, 16, 16);
////g.FillEllipse(Brushes.Red, subsubImgRect);
//g.DrawImage(this.TimeLineIcons.Images[2], subsubImgRect);
Brush itemIconBrush = Brushes.Red;
switch (subsubItem.Timeliness)
{
case Timeliness.Normal:
itemIconBrush = Brushes.Green;
break;
case Timeliness.Yellow:
itemIconBrush = Brushes.Yellow;
break;
case Timeliness.Orange:
itemIconBrush = Brushes.Orange;
break;
case Timeliness.Red:
itemIconBrush = Brushes.Red;
break;
case Timeliness.Dark:
itemIconBrush = Brushes.Gray;
break;
case Timeliness.Black:
itemIconBrush = Brushes.Black;
break;
}
int m = 20;
Rectangle subsubImgRect = Rectangle.Empty;
if (subsubItem.Icon != null)
{
if (subsubItem.Icon.Height == 16)
{
m = 20;
subsubImgRect = new Rectangle(56 + 0, top + 3, 16, 16);
}
if (subsubItem.Icon.Height == 24)
{
m = 28;
subsubImgRect = new Rectangle(56 + 0, top + 3, 24, 24);
}
else
{
throw new Exception("只支持16*16、24*24大小的图标");
}
g.DrawImage(subsubItem.Icon, subsubImgRect);
}
else
{
if(!string.IsNullOrEmpty(subsubItem.PersonName))
{
m = 28;
subsubImgRect = new Rectangle(56 + 0, top + 3, 24, 24);
}
else
{
m = 20;
subsubImgRect = new Rectangle(56 + 0, top + 7, 16, 16);
}
g.FillEllipse(itemIconBrush, subsubImgRect);
if (!string.IsNullOrEmpty(subsubItem.PersonName))
{
Brush showNameBrush = Brushes.White;
Font showNameFont = new Font("微软雅黑", 8, FontStyle.Bold);
if (itemIconBrush == Brushes.Red ||
itemIconBrush == Brushes.Yellow)
{
showNameBrush = Brushes.Black;
}
g.DrawString(subsubItem.PersonName, showNameFont, showNameBrush, subsubImgRect, sf);
}
}
//Rectangle subsubTitleRect = new Rectangle(56 + 20, top, bound.Width - 84 - 60, 32);
Rectangle subsubTitleRect = new Rectangle(56 + m, top, bound.Width - 84 - 60, 32);
//g.DrawRectangle(new Pen(Color.Orange), subsubTitleRect);
//g.DrawString((i + 1) + "、" + subItem.Title, this.Font, Brushes.Red, subTitleRect, subSf);
//g.DrawString(subsubItem.Title, this.Font, drawTitleBrush, subsubTitleRect, subSf);
TextRenderer.DrawText(g, subsubItem.Title, this.Font, subsubTitleRect, drawTitleColor, TextFormatFlags.Left | TextFormatFlags.WordEllipsis | TextFormatFlags.VerticalCenter);
if (_isEditModel && subsubItem.Selected)
{
//绘制删除按扭
Size subsubTitleSize = TextRenderer.MeasureText(g, subsubItem.Title, this.Font);
subsubItem.EditRect = new Rectangle(subsubTitleRect.X + subsubTitleSize.Width + 2, top + 8, 16, 16);
subsubItem.DeleteRect = new Rectangle(subsubTitleRect.X + subsubTitleSize.Width + 2 + 16 + 4, top + 8, 16, 16);
}
Rectangle subsubTimeRect = new Rectangle(bound.Width - 64, top, 56, 32);
//g.FillRectangle(Brushes.Green, subsubTimeRect);
//g.DrawString((i + 1) + "、" + subItem.Title, this.Font, Brushes.Red, subTitleRect, subSf);
g.DrawString(subsubItem.DateTime.ToString("HH:mm:ss"), this.Font, drawTitleBrush, subsubTimeRect, subSf);
if (!string.IsNullOrEmpty(subsubItem.Summary))
{
Font drawSummaryFont = this.Font;
Brush drawSummaryBrush = Brushes.Gray;
Color drawSummaryColor = Color.Gray;
if (subsubItem.Selected)
{
drawSummaryBrush = new SolidBrush(SystemColors.ControlDark);
//drawSummaryFont = new Font(this.Font, FontStyle.Italic);
drawSummaryColor = SystemColors.ControlDark;
}
top = top + 32;
Rectangle subsubSummaryRect = new Rectangle(56, top, bound.Width - 64, 26);
//g.DrawRectangle(Pens.Red, subsubSummaryRect);
//g.DrawString(subsubItem.Summary, drawSummaryFont, drawSummaryBrush, subsubSummaryRect, subSf);
TextRenderer.DrawText(g, subsubItem.Summary, drawSummaryFont, subsubSummaryRect, drawSummaryColor, TextFormatFlags.Left | TextFormatFlags.WordEllipsis | TextFormatFlags.VerticalCenter);
}
subsubItem.ClickRect = DateTimeItemClickRect;
g.DrawLine(new Pen(SystemColors.ControlLight) { DashStyle = System.Drawing.Drawing2D.DashStyle.Dot }, 56, top + 32, bound.Width - 10, top + 32);
if (_isEditModel && subsubItem.Selected)
{
//switch (subsubItem.ButtonState)
//{
// case 1:
// g.FillRectangle(new SolidBrush(Color.Orange), subsubItem.EditRect);
// g.FillRectangle(new SolidBrush(Color.FromArgb(240, 245, 249)), subsubItem.DeleteRect);
// break;
// case 2:
// g.FillRectangle(new SolidBrush(Color.FromArgb(240, 245, 249)), subsubItem.EditRect);
// g.FillRectangle(new SolidBrush(Color.Orange), subsubItem.DeleteRect);
// break;
// default:
// g.FillRectangle(new SolidBrush(Color.FromArgb(240, 245, 249)), subsubItem.EditRect);
// g.FillRectangle(new SolidBrush(Color.FromArgb(240, 245, 249)), subsubItem.DeleteRect);
// break;
//}
g.FillRectangle(new SolidBrush(Color.FromArgb(240, 245, 249)), subsubItem.EditRect);
g.FillRectangle(new SolidBrush(Color.FromArgb(240, 245, 249)), subsubItem.DeleteRect);
//绘制编辑按扭
g.DrawImage(this.TimeLineIcons.Images[0], subsubItem.EditRect);
//绘制删除按扭
g.DrawImage(this.TimeLineIcons.Images[1], subsubItem.DeleteRect);
}
}
}
}
}
StringFormat sf2 = new StringFormat();
sf2.LineAlignment = StringAlignment.Center;
Rectangle itemTitleRect = new Rectangle(56, bound.Top + 5, bound.Width - 64, 36);
//g.DrawRectangle(new Pen(Color.Orange), itemTitleRect);
//g.DrawString("共计 " + (item.List == null ? 0 : item.List.Count()) + " 个事项", this.Font, Brushes.Black, itemTitleRect, sf2);
}