Reputation: 23
In my program I have a custom TPanel
that slides out from above and has buttons and images on it. It slides out fine but when I go to hide it, it is very slow. I have tried several methods and all are the same result. If you notice below I tried Redraw thinking I could just redraw the trailing rect but this call redraws the entire form as does all the other methods I have tried. I even tried using scroll. Am I calling it wrong or is there a better way to just update the form part that needs updating as the panel moves up?
while z>mypanels[panel].Fstarttop do
begin
if z-x<mypanels[panel].Fstarttop then z:=mypanels[panel].Fstarttop else z:=z-x;
updaterect:=Rect(mypanels[panel].left,z+mypanels[panel].height,mypanels[panel].left+mypanels[panel].width,mypanels[panel].top+mypanels[panel].height);
mypanels[panel].top:=z;
//mypanels[panel].Repaint;
//Application.ProcessMessages;
//mypanels[panel].ScrollBy(0,-x);
//InvalidateRect(form1.Handle,@updaterect,FALSE);
//Application.ProcessMessages;
//RedrawWindow(form1.Handle,@updaterect, 0, RDW_UPDATENOW);
//form1.refresh;
end;
Upvotes: 2
Views: 2181
Reputation: 43649
Moving a panel should not take long. Also, to update the parent of the panel, a call to Form.Update
should be just fine. To force a redraw of only a portion of a form, a call to InvalidateRect
should do, as you have already done (try clearing the background though).
Possible reasons for the delay and/or smudging are:
Form.OnPaint
,Anchors
, Align
, and/or Constraints
of panel and/or form are contradicting or result in a chain-reaction (in this case, try DisableAlign
and EnableAlign
),updaterect
variable is the new rectangle instead of the previous one,Upvotes: 3
Reputation: 79
Another approach it to use windows update regions. Your Tpanel as a "handle" property, that you can use with invalidateRect.
Normally the vcl will redraw :
- the background of your panel
- Only the controls in the invalidated rectangle
Upvotes: 1
Reputation: 36082
Try setting the parent TForm's DoubleBuffered property to True. This will help reduce the execution cost of redraws and may reduce the jitters of your close-up animation.
Upvotes: 0