Canvas Not Painting On Demand lazarus / 39-Graphics ---------------------------------------------------------------------- Dan3468298 · 2020-07-17 18:47 My understanding is that all canvas paint-related code should go in its OnPaint event since the OS may call a refresh at any time (for example, if another window is moved).  I cannot get a TPanel to refresh so I must be missing something.  Here's the code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls ; type   { TForm1 }   TForm1 = class(TForm)    Edit1: TEdit;    Label1: TLabel;    Panel1: TPanel;    procedure Edit1Change(Sender: TObject);    procedure Panel1Paint(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Edit1Change(Sender: TObject);begin  Label1.Caption := Edit1.Text;  Panel1.Canvas.Refresh; //trigger a canvas OnPaint eventend; procedure TForm1.Panel1Paint(Sender: TObject);begin  Panel1.Canvas.Font.Size := 10;  Panel1.Canvas.Pen.Color := clBlack;  Panel1.Canvas.Brush.Style := bsClear;  Panel1.Canvas.TextOut(20, 20, Edit1.Text);  Panel1.Canvas.Refresh;end; end. ---------------------------------------------------------------------- howardpc · 2020-07-17 19:09 Try this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Edit1Change(Sender: TObject);begin  Label1.Caption := Edit1.Text;  Panel1.Invalidate;end; procedure TForm1.Panel1Paint(Sender: TObject);begin  with Panel1.Canvas do    begin      if Font.Size <> 10 then        Font.Size := 10;      if Pen.Color <> clBlack then        Pen.Color := clBlack;      if Brush.Style <> bsClear then        Brush.Style := bsClear;      TextOut(20, 20, Edit1.Text);    end;end; ---------------------------------------------------------------------- Dan3468298 · 2020-07-17 19:38 My aim is to have the canvas repaint on every Edit1 Change event.   Is there a way to do this?   Thx ---------------------------------------------------------------------- howardpc · 2020-07-17 20:01 I tested the above code on Linux, and the panel is repainted at every Edit1 OnChange event. If this is not happening on MacOS, then you need to file a bug report. ---------------------------------------------------------------------- wp · 2020-07-17 20:14 Maybe you don't understand what "Invalidate" means. I agree, it is a strange word... It means that the screen display of the control is no longer valid, a repaint command is put into the message queue of the OS and the control is repainted the next time when the program is idle. There are other direct painting methods (Control.Refresh, Control.Refresh) but Invalidate has the advantage that only the last drawing command is executed if several of them would have found their way into the message queue (and this happens quite often). So the rule is: whenever you want a control to be redrawn call its Invalidate method. ---------------------------------------------------------------------- Dan3468298 · 2020-07-17 21:34 On second try it works now. thanks.  Strange name "Invalidate" I thought it was a joke to remove that line! ---------------------------------------------------------------------- winni · 2020-07-17 22:51 For jokes there is Java. Pascal is serious! Winni