需要你的帮助(我一直在寻找)。我在德尔福西雅图,试图平滑调整表单底部的大小。就我而言,“调整大小”只是有点折叠/展开,如下所示:
我怎样才能意识到这一点?
我尝试过使用 TTimer:
procedure TForm1.Timer1Timer(Sender: TObject);
var
h, t: integer;
begin
t := Button10.Top + Button10.Height + 10; //slide TForm from/to this point
if t > h then
begin
h := h + 1;
Form1.Height := h;
end
else
begin
Timer1.Enabled := false;
end;
end;
...但它看起来非常简单(没有加速/减速),即使间隔很小,工作速度也很慢。
没有必要让 TTimers 变得复杂。这将处理折叠和展开的形式,包括您所需的平滑度。
诀窍是通过在每次迭代时采用目标大小 - 当前高度和 div 3 来计算每个步骤,这都会加速初始折叠或扩展,然后随着表单接近其目标大小而减速。
procedure TForm1.SmoothResizeFormTo(const ToSize: integer);
var
CurrentHeight: integer;
Step: integer;
begin
while Height <> ToSize do
begin
CurrentHeight := Form1.Height;
// this is the trick which both accelerates initially then
// decelerates as the form reaches its target size
Step := (ToSize - CurrentHeight) div 3;
// this allows for both collapse and expand by using Absolute
// calculated value
if (Step = 0) and (Abs(ToSize - CurrentHeight) > 0) then
begin
Step := ToSize - CurrentHeight;
Sleep(50); // adjust for smoothness
end;
if Step <> 0 then
begin
Height := Height + Step;
sleep(50); // adjust for smoothness
end;
end;
end;
procedure TForm1.btnCollapseClick(Sender: TObject);
begin
SmoothResizeFormTo(100);
end;
procedure TForm1.btnExpandClick(Sender: TObject);
begin
SmoothResizeFormTo(800);
end;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)