对于web方向的工作流,一直在用gooflow对于目前我的winform开发平台却没有较好的工作流组件。
针对目前的项目经验告诉我们。一个工作流控件是很必要的。 当然在 winform方面的工作流第三方组件在网上找了很久,也没有发现自己比较心仪的组件。
对于工作流组件通过web方式来实现具有绝对的优势。我的这套winform平台当然也不能少了工作流组件。
通过winform来实现自己的工作流组件,目前我想到的指能通过GDI+重绘的方式来实现工作流的方案。
说干就干,如下图这是我通过GDI+绘制的工作流控件:
设计思想:
控件中我们需要一些定义的节点:如开始、结束、自定义节点、画线,和一个内容画布组成
通过抽象出线、点、以及item。进行重绘。
画布进行双缓冲来解决绘制时导致的出线闪屏问题。
简单介绍:
画布中的网格绘制方法:
var gridPen = new Pen(Color.Silver) { DashStyle = DashStyle.Custom, DashPattern = new float[] { 2f, 2f } }; for (int column = 0; column < (int)Math.Ceiling((double)this.Width / (double)gridAverage); column++) { bufferGraphics.DrawLine(gridPen, new Point(column * gridAverage, 0), new Point(column * gridAverage, this.Height)); } for (int row = 0; row < (int)Math.Ceiling((double)this.Height / (double)gridAverage); row++) { bufferGraphics.DrawLine(gridPen, new Point(0, row * gridAverage), new Point(this.Width, row * gridAverage)); }
绘制节点抽象类型代码:
public enum ItemType { /// <summary> /// 开始 /// </summary> Start, /// <summary> /// 工作流 /// </summary> Custom, /// <summary> /// 线 /// </summary> Line, /// <summary> /// 结束 /// </summary> End }
绘制连线
public void DrawLine(Graphics grp, Pen pen) { if (m_startPoint == null || m_endPoint == null) return; var startX = m_startPoint.ItemLocate.X + m_startPoint.ItemImage.Width / 2; var startY = m_startPoint.ItemLocate.Y + m_startPoint.ItemImage.Height / 2; var endX = m_endPoint.ItemLocate.X + m_endPoint.ItemImage.Width / 2; var endY = m_endPoint.ItemLocate.Y + m_endPoint.ItemImage.Height / 2; #region 计算开始点位置 if (m_startPoint.ItemLocate.X < m_endPoint.ItemLocate.X) { if (m_startPoint.ItemLocate.Y < m_endPoint.ItemLocate.Y - m_startPoint.ItemLocate.Y) { startX = m_startPoint.ItemLocate.X + m_startPoint.ItemImage.Width / 2; startY = m_startPoint.ItemLocate.Y + m_startPoint.ItemImage.Height; } else if (m_startPoint.ItemLocate.Y < m_endPoint.ItemLocate.Y + m_endPoint.ItemImage.Height) { startX = m_startPoint.ItemLocate.X + m_startPoint.ItemImage.Width; startY = m_startPoint.ItemLocate.Y + m_startPoint.ItemImage.Height / 2; } else { startX = m_startPoint.ItemLocate.X + m_startPoint.ItemImage.Width / 2; startY = m_startPoint.ItemLocate.Y; } } else { if (m_startPoint.ItemLocate.Y < m_endPoint.ItemLocate.Y - m_startPoint.ItemLocate.Y) { startX = m_startPoint.ItemLocate.X + m_startPoint.ItemImage.Width / 2; startY = m_startPoint.ItemLocate.Y + m_startPoint.ItemImage.Height; } else if (m_startPoint.ItemLocate.Y < m_endPoint.ItemLocate.Y + m_endPoint.ItemImage.Height) { startX = m_startPoint.ItemLocate.X; startY = m_startPoint.ItemLocate.Y + m_startPoint.ItemImage.Height / 2; } else { startX = m_startPoint.ItemLocate.X + m_startPoint.ItemImage.Width / 2; startY = m_startPoint.ItemLocate.Y; } } #endregion #region 计算结束点位置 if (m_startPoint.ItemLocate.X < m_endPoint.ItemLocate.X) { if (m_startPoint.ItemLocate.Y < m_endPoint.ItemLocate.Y - m_startPoint.ItemLocate.Y) { endX = m_endPoint.ItemLocate.X + m_endPoint.ItemImage.Width / 2; endY = m_endPoint.ItemLocate.Y; } else if (m_startPoint.ItemLocate.Y < m_endPoint.ItemLocate.Y + m_endPoint.ItemImage.Height) { endX = m_endPoint.ItemLocate.X; endY = m_endPoint.ItemLocate.Y + m_endPoint.ItemImage.Height / 2; } else { endX = m_endPoint.ItemLocate.X + m_endPoint.ItemImage.Width / 2; endY = m_endPoint.ItemLocate.Y + m_endPoint.ItemImage.Height; } } else { if (m_startPoint.ItemLocate.Y < m_endPoint.ItemLocate.Y - m_startPoint.ItemLocate.Y) { endX = m_endPoint.ItemLocate.X + m_endPoint.ItemImage.Width / 2; endY = m_endPoint.ItemLocate.Y; } else if (m_startPoint.ItemLocate.Y < m_endPoint.ItemLocate.Y + m_endPoint.ItemImage.Height) { endX = m_endPoint.ItemLocate.X + m_endPoint.ItemImage.Width; endY = m_endPoint.ItemLocate.Y + m_endPoint.ItemImage.Height / 2; } else { endX = m_endPoint.ItemLocate.X + m_endPoint.ItemImage.Width / 2; endY = m_endPoint.ItemLocate.Y + m_endPoint.ItemImage.Height; } } #endregion var startPoint = new Point(startX, startY); var endPoint = new Point(endX, endY); grp.DrawLine(pen, startPoint, endPoint); }
通过一点一滴的付出,每个时间点都会看到他的完善。同时也期待着的他的成长。