功能 – 德尔福:平滑崩溃/扩展形式
发布时间:2020-12-15 09:30:39 所属栏目:大数据 来源:网络整理
导读:需要你的帮助(我一直在寻找).我在德尔福西雅图,尝试顺利调整表格的底部.在我的情况下,“调整大
需要你的帮助(我一直在寻找).我在德尔福西雅图,尝试顺利调整表格的底部.在我的情况下,“调整大小”只是有点崩溃/扩展,如下所示:
我怎么能意识到这一点? 我尝试过使用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; …但它看起来非常简单(没有加速/减速),即使间隔很小也行动缓慢. 解决方法
Timors没有必要变得复杂.这将包括折叠和扩展形式,包括您需要的平滑度.
诀窍是通过在每次迭代中获取目标大小 – 当前高度和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; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |