ListView類比的簡單流程圖介面

來源:互聯網
上載者:User
昨天花了點時間以ListView為基礎,為各ListItem添加了串連箭頭,類比出一個簡單的流程圖介面,拖動表徵圖時亦會調整重繪連線。

重點在繪箭頭連接線用的DrawFlowLine函數上,有需要的朋友可自己擴充一下:
  1. //CommCtrl, GraphUtil
  2. procedure DrawFlowLine(ACanvas: TCanvas; SrcItem, DestItem: TListItem);
  3. var
  4.     SrcPt, DestPt: TPoint;
  5.     SrcRect, DestRect: TRect;
  6.     ArrowDirect: TScrollDirection;
  7. begin
  8.     //取對象的中點供比較之用
  9.     ListView_GetItemRect(SrcItem.ListView.Handle, SrcItem.Index, SrcRect, 0);
  10.     ListView_GetItemRect(DestItem.ListView.Handle, DestItem.Index, DestRect, 0);
  11.     SrcPt.X := SrcRect.Left + (SrcRect.Right - SrcRect.Left) div 2;
  12.     SrcPt.Y := SrcRect.Top + (SrcRect.Bottom - SrcRect.Top) div 2;
  13.     DestPt.X := DestRect.Left + (DestRect.Right - DestRect.Left) div 2;
  14.     DestPt.Y := DestRect.Top + (DestRect.Bottom - DestRect.Top) div 2;
  15.     //通過中點的比較決定箭頭方向
  16.     if Abs(SrcPt.X - DestPt.X) > Abs(SrcPt.Y - DestPt.Y) then begin
  17.         if SrcPt.X <= DestPt.X then ArrowDirect := sdRight
  18.         else ArrowDirect := sdLeft;
  19.     end else begin
  20.         if SrcPt.Y <= DestPt.Y then ArrowDirect := sdDown
  21.         else ArrowDirect := sdUp;
  22.     end;
  23.     //計算線段的起點與終點
  24.     case ArrowDirect of
  25.         sdLeft: begin
  26.             SrcPt := Point(DestRect.Right-16, DestRect.Top + ((DestRect.Bottom-DestRect.Top) div 2));
  27.             DestPt := Point(SrcRect.Left+16, SrcRect.Top + ((SrcRect.Bottom-SrcRect.Top) div 2));
  28.         end;
  29.         sdRight: begin
  30.             SrcPt := Point(SrcRect.Right-16, SrcRect.Top + ((SrcRect.Bottom-SrcRect.Top) div 2));
  31.             DestPt := Point(DestRect.Left+16, DestRect.Top + ((DestRect.Bottom-DestRect.Top) div 2));
  32.         end;
  33.         sdUp: begin
  34.             SrcPt := Point(DestRect.Left + ((DestRect.Right-DestRect.Left) div 2), DestRect.Bottom+2);
  35.             DestPt := Point(SrcRect.Left + ((SrcRect.Right-SrcRect.Left) div 2), SrcRect.Top);
  36.         end;
  37.         sdDown: begin
  38.             SrcPt := Point(SrcRect.Left + ((SrcRect.Right-SrcRect.Left) div 2), SrcRect.Bottom);
  39.             DestPt := Point(DestRect.Left + ((DestRect.Right-DestRect.Left) div 2), DestRect.Top);
  40.         end;
  41.     end;
  42.     //繪製連線
  43.     ACanvas.Pen.Width := 2;
  44.     case ArrowDirect of
  45.         sdLeft, sdRight: begin
  46.             ACanvas.MoveTo(SrcPt.X, SrcPt.Y);
  47.             ACanvas.LineTo(SrcPt.X + 8, SrcPt.Y);
  48.             ACanvas.LineTo(DestPt.X - 8, DestPt.Y);
  49.             ACanvas.LineTo(DestPt.X , DestPt.Y);
  50.         end;
  51.         sdUp, sdDown: begin
  52.             ACanvas.MoveTo(SrcPt.X, SrcPt.Y);
  53.             ACanvas.LineTo(SrcPt.X, SrcPt.Y + 8);
  54.             ACanvas.LineTo(DestPt.X, DestPt.Y - 8);
  55.             ACanvas.LineTo(DestPt.X, DestPt.Y - 2);
  56.         end;
  57.     end;
  58.     //繪製箭頭
  59.     case ArrowDirect of
  60.         sdLeft: DrawArrow(ACanvas, sdLeft, Point(SrcPt.X - 2, SrcPt.Y - 5), 4);
  61.         sdRight: DrawArrow(ACanvas, sdRight, Point(DestPt.X - 2, DestPt.Y - 5), 4);
  62.         sdUp: DrawArrow(ACanvas, sdUp, Point(SrcPt.X - 5, SrcPt.Y-2), 4);
  63.         sdDown: DrawArrow(ACanvas, sdDown, Point(DestPt.X - 5, DestPt.Y - 4), 4);
  64.     end;
  65. end;

完整的程式已上傳到我的資源中:http://download.csdn.net/source/758098

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.