Support,
Is there any way to automatically re-size all shapes within a TTree proportionately, to ensure they are visible and fit within within the TTree control bounds without scrolling, when the TTree control is resized at runtime?
Kind Regards,
Keith
Autosize/autofit TTree objects- any solution yet?
Hi Keith and Tom,
since I was struggling with this for quite some time, here is the solution which works sufficiently well for us:
in the onResize handler of a TTree add the follwing code:
Sorry, if that code is a bit out of context, but it is part of some larger code ... you should get the idea, if not let me know.
Best
Markus
since I was struggling with this for quite some time, here is the solution which works sufficiently well for us:
in the onResize handler of a TTree add the follwing code:
Code: Select all
if not calcContentSize then
begin
// the content size is independent of the zoom factor
hCont:=getTreeContentHeight;
wCont:=getTreeContentWidth;
end else
begin
bound:=Rect(high(integer), high(integer), low(integer), low(integer));
for i:=0 to FTree.Roots.Count-1 do
begin
bound.Left:=min(bound.Left, FTree.Roots[i].X0);
bound.Top:=min(bound.Top, FTree.Roots[i].Y0);
bound.Right:=max(bound.Right, FTree.Roots[i].X0+FTree.Roots[i].Width);
bound.Bottom:=max(bound.Bottom, FTree.Roots[i].Y0+FTree.Roots[i].Height);
end;
if bound.Right<>low(integer) then
wCont:=bound.Right;
if bound.Bottom<>low(integer) then
hCont:=bound.Bottom;
end;
if abs(hCont)+abs(wCont)=0 then
exit;
FTree.BeginUpdate;
try
z1:=FTree.height/hCont*100;
z2:=FTree.width/wCont*100;
zoom:=min(z1,z2);
FTree.View3DOptions.Zoom:=trunc(zoom);
FTree.View3DOptions.HorizOffset:=round((FTree.Width/2-wCont/2)*FTree.View3DOptions.Zoom*0.01);
FTree.View3DOptions.VertOffset:=round((FTree.Height/2-hCont/2)*FTree.View3DOptions.Zoom*0.01);
finally
FTree.EndUpdate;
end;
function getTreeContentWidth:integer;
begin
result:=FTree.TotalBounds.Right-FTree.TotalBounds.Left;
end;
function getTreeContentHeight:integer;
begin
result:=FTree.TotalBounds.Bottom-FTree.TotalBounds.Top;
end;
Best
Markus