ListView模拟的简单流程图界面

昨天花了点时间以ListView为基础,为各ListItem添加了连接箭头,模拟出一个简单的流程图界面,拖动图标时亦会调整重绘连线。
重点在绘箭头连接线用的DrawFlowLine函数上,有需要的朋友可自己扩展一下:
  1. //CommCtrl,GraphUtil
  2. procedureDrawFlowLine(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)div2;
  12. SrcPt.Y:=SrcRect.Top+(SrcRect.Bottom-SrcRect.Top)div2;
  13. DestPt.X:=DestRect.Left+(DestRect.Right-DestRect.Left)div2;
  14. DestPt.Y:=DestRect.Top+(DestRect.Bottom-DestRect.Top)div2;
  15. //通过中点的比较决定箭头方向
  16. ifAbs(SrcPt.X-DestPt.X)>Abs(SrcPt.Y-DestPt.Y)thenbegin
  17. ifSrcPt.X<=DestPt.XthenArrowDirect:=sdRight
  18. elseArrowDirect:=sdLeft;
  19. endelsebegin
  20. ifSrcPt.Y<=DestPt.YthenArrowDirect:=sdDown
  21. elseArrowDirect:=sdUp;
  22. end;
  23. //计算线段的起点与终点
  24. caseArrowDirectof
  25. sdLeft:begin
  26. SrcPt:=Point(DestRect.Right-16,DestRect.Top+((DestRect.Bottom-DestRect.Top)div2));
  27. DestPt:=Point(SrcRect.Left+16,SrcRect.Top+((SrcRect.Bottom-SrcRect.Top)div2));
  28. end;
  29. sdRight:begin
  30. SrcPt:=Point(SrcRect.Right-16,SrcRect.Top+((SrcRect.Bottom-SrcRect.Top)div2));
  31. DestPt:=Point(DestRect.Left+16,DestRect.Top+((DestRect.Bottom-DestRect.Top)div2));
  32. end;
  33. sdUp:begin
  34. SrcPt:=Point(DestRect.Left+((DestRect.Right-DestRect.Left)div2),DestRect.Bottom+2);
  35. DestPt:=Point(SrcRect.Left+((SrcRect.Right-SrcRect.Left)div2),SrcRect.Top);
  36. end;
  37. sdDown:begin
  38. SrcPt:=Point(SrcRect.Left+((SrcRect.Right-SrcRect.Left)div2),SrcRect.Bottom);
  39. DestPt:=Point(DestRect.Left+((DestRect.Right-DestRect.Left)div2),DestRect.Top);
  40. end;
  41. end;
  42. //绘制连线
  43. ACanvas.Pen.Width:=2;
  44. caseArrowDirectof
  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. caseArrowDirectof
  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

<!-- google_ad_client = "pub-5395599807454886"; /* 468x15文字连接广告, 创建于 08-11-21 */ google_ad_slot = "5196248270"; google_ad_width = 468; google_ad_height = 15; //-->
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值