제목 그대로 TreeView의 내용을 전부 출력하는 방법 좀 갈켜주세여
검색을 해서 그대로 해봤는데....
중간에 몇장이 빠져있네요... 글씨도 넘 큰거같고...
소스를 이해하기도 힘드네여 초보라서리.......
혹시 알고 계시는 분 있으시면 답변 꼭 부탁드립니다.
즐거운 하루 되세여
소스도 같이 올립니다.
TTreePrint = class
private
FTreeView: TTreeView;
nX, nY: integer;
nOffsetX, nOffsetY: integer;
nGap: integer;
nLineWidth: integer;
nHeight: integer;
protected
procedure PrintTreeViewNode(tn: TTreeNode);
public
constructor Create(ATreeView: TTreeView); reintroduce;
procedure PrintTreeView;
procedure AdjustLine;
procedure DrawParentLine(tn: TTreeNode);
published
property XOffset : integer read nOffsetX write nOffsetX;
property YOffset : integer read nOffsetY write nOffsetY;
property Gap : integer read nGap write nGap;
property LineWidth: integer read nLineWidth write nLineWidth;
end;
procedure TKIT_A05_F.SpeedButton2Click(Sender: TObject);
var
tp: TTreePrint;
begin
tp := TTreePrint.Create(TreeView1);
try
tp.PrintTreeView;
finally
tp.Free;
end;
end;
constructor TTreePrint.Create(ATreeView: TTreeView);
begin
nOffsetX := 0;
nOffsetY := 0;
nGap := 150;
nLineWidth := 100;
FTreeView := ATreeView;
inherited Create;
end;
procedure TTreePrint.AdjustLine;
begin
if nY < nHeight - Printer.PageHeight then begin
Printer.NewPage;
nY := -nOffsetY;
end
else nY := nY - nHeight;
end;
procedure TTreePrint.DrawParentLine(tn: TTreeNode);
var
ParentNode: TTreeNode;
begin
ParentNode := tn.Parent;
if Assigned(ParentNode) then begin
if ParentNode.getNextSibling <> nil then begin
Printer.Canvas.MoveTo(nOffsetX + ParentNode.Level*nGap, nY);
Printer.Canvas.LineTo(nOffsetX + ParentNode.Level*nGap, nY - nHeight);
end;
DrawParentLine(ParentNode);
end;
end;
procedure TTreePrint.PrintTreeViewNode(tn: TTreeNode);
begin
if Assigned(tn) then begin
AdjustLine;
DrawParentLine(tn);
nX := nOffsetX + tn.Level*nGap;
if tn = FTreeView.Items.GetFirstNode then
printer.Canvas.MoveTo(nX, nY - nHeight div 2)
else Printer.Canvas.MoveTo(nX, nY);
if tn.getNextSibling <> nil then begin
Printer.Canvas.LineTo(nX, nY - nHeight);
Printer.Canvas.MoveTo(nX, nY - nHeight div 2);
end
else Printer.Canvas.LineTo(nX, nY - nHeight div 2);
Printer.Canvas.LineTo(nX + nLineWidth, nY - nHeight div 2);
Printer.Canvas.TextOut(nX + nLineWidth + 1, nY, tn.Text);
PrintTreeViewNode(tn.getFirstChild);
PrintTreeViewNode(tn.GetNextSibling);
end;
end;
procedure TTreePrint.PrintTreeView;
var
nOldMapMode: integer;
begin
nX := nOffsetX;
nY := -nOffsetY;
Printer.BeginDoc;
nOldMapMode := SetMapMode(Printer.Canvas.Handle, MM_LOMETRIC);
nHeight := Printer.Canvas.TextHeight('');
try
PrintTreeViewNode(FTreeView.Items.GetFirstNode);
finally
SetMapMode(Printer.Canvas.Handle, nOldMapMode);
Printer.EndDoc;
end;
end;