winform快速開發平臺 -> 工做流組件(仿GooFlow)

     對於web方向的工做流,一直在用gooflow對於目前個人winform開發平臺卻沒有較好的工做流組件。html

   針對目前的項目經驗告訴咱們。一個工做流控件是很必要的。 固然在winform方面的工做流第三方組件在網上找了好久,也沒有發現本身比較心儀的組件。 web

     對於工做流組件經過web方式來實現具備絕對的優點。個人這套winform平臺固然也不能少了工做流組件。 post

     經過winform來實現本身的工做流組件,目前我想到的指能經過GDI+重繪的方式來實現工做流的方案。this

  說幹就幹,以下圖這是我經過GDI+繪製的工做流控件: url

      圖片

設計思想:spa

    控件中咱們須要一些定義的節點:如開始、結束、自定義節點、畫線,和一個內容畫布組成

    經過抽象出線、點、以及item。進行重繪。

    畫布進行雙緩衝來解決繪製時致使的出線閃屏問題。 設計

簡單介紹:orm

    畫布中的網格繪製方法:htm

 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));
} 

  繪製節點抽象類型代碼:blog

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);
}

  

經過一點一滴的付出,每一個時間點都會看到他的完善。同時也期待着的他的成長。

Winform快速開發平臺系列:

官網鏈接

1.winform快速開發平臺 -> 讓有限的資源創造無限的價值!

2.winform快速開發平臺 -> 基礎組件之分頁控件

3.winform快速開發平臺 -> 綁定ComboBox數據控件

4.winform快速開發平臺 -> 工做流組件(仿GooFlow)

5.winform快速開發平臺 -> 通用權限管理之動態菜單

相關文章
相關標籤/搜索