user1704980
user1704980

Reputation: 23

Repaint small part of form only using Delphi?

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

Answers (3)

NGLN
NGLN

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:

  • you do some extensive own drawing in 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),
  • the form is not the immediate parent of the panel,
  • the panel is over some other control,
  • your updaterect variable is the new rectangle instead of the previous one,
  • something else in your code and/or calling routine,
  • any combination of the above.

Upvotes: 3

Sisko
Sisko

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

dthorpe
dthorpe

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

Related Questions