Recent

Author Topic: Redrawing form  (Read 248 times)

pascal111

  • Full Member
  • ***
  • Posts: 121
Redrawing form
« on: April 21, 2021, 03:38:06 am »
I'm trying in the next piece of code to delay the drawing of line of pixels to see some motion, but I failed to make the form to redraw itself again each determined time of "delay" procedure:


Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormPaint(Sender: TObject);
  2. var
  3.  
  4.   i:integer;
  5.  
  6. begin
  7.  
  8.  
  9.  
  10.   for i:=1 to 100 do
  11.   begin
  12.  
  13.     canvas.Pixels[i,10]:=clblue;
  14.     self.update;
  15.     delay(100);
  16.  
  17.   end;
  18.  
  19.  
  20.  
  21.  
  22.  
  23. end;                
  24.  


engkin

  • Hero Member
  • *****
  • Posts: 2692
Re: Redrawing form
« Reply #1 on: April 21, 2021, 04:11:11 am »
After delay call Application.ProcessMessages.

The correct way is to use a timer.

If you draw on the form, it will not retain the image when covered with some other window.
« Last Edit: April 21, 2021, 04:17:35 am by engkin »

engkin

  • Hero Member
  • *****
  • Posts: 2692
Re: Redrawing form
« Reply #2 on: April 21, 2021, 04:59:46 am »
Check attached project

pascal111

  • Full Member
  • ***
  • Posts: 121
Re: Redrawing form
« Reply #3 on: April 21, 2021, 01:25:57 pm »
I made some changes depending on attached project "simple", and it works.


Code: Pascal  [Select][+][-]
  1.  
  2. var
  3.   Form1: TForm1;
  4.   x:integer;    
  5.  
  6.  
  7. procedure TForm1.FormPaint(Sender: TObject);
  8.  
  9. begin
  10.  
  11.  
  12.      canvas.Pixels[x,10]:=clblue;
  13.  
  14.  
  15.  
  16. end;
  17.  
  18. procedure TForm1.Timer1Timer(Sender: TObject);
  19.  
  20.  
  21. begin
  22.  
  23.   if x>=100 then
  24.   exit
  25.   else
  26.     inc(x);
  27.  
  28.  
  29.  
  30.   Invalidate;
  31.  
  32.  
  33. end;              
  34.  


With modifying "interval" property of the timer.

 

TinyPortal © 2005-2018