How to temporarily stop a control from being paint?

后端 未结 4 2163
伪装坚强ぢ
伪装坚强ぢ 2021-02-09 01:43

We have a win control object which moves its clients to some other coordiantes. The problem is, when there are too many children - for example 500 controls - the code is really

4条回答
  •  旧巷少年郎
    2021-02-09 02:09

    To speed up you should set the Visible property of you WinControl to False during child movement to avoid repainting.

    Together with SetBounds you will get the best from moving the child controls.

    procedure TForm1.MoveControls( AWinControl : TWinControl; ADX, ADY : Integer );
    var
      LIdx : Integer;
    begin
      AWinControl.Visible := False;
      try
        for LIdx := 0 to Pred( AWinControl.ControlCount ) do
          with AWinControl.Controls[LIdx] do
            begin
              SetBounds( Left + ADX, Top + ADY, Width, Height );
            end;
      finally
        AWinControl.Visible := True;
      end;
    end;
    

    BTW As David suggested, moving the parent is much faster than each child.

提交回复
热议问题