Search code examples
freepascallazarus

What is the name of the component in Lazarus, which name in Delphi is "Canvas"?


I want to create a paint application in Lazarus, but I don't see the appropriate control, which I can use as a canvas in Deplhi. What is its name ?


Solution

  • There is no Canvas component in Delphi, but if you're looking for a component, which you can use for custom drawing in your application, then you're looking for the TPaintBox control (the same name of this component is used also in Delphi). In Lazarus you can find it here in the component palette:

    enter image description here

    In newer versions of Lazarus IDE you can advance from the component selector to find components by name. If you press CTRL + ALT + P, you'll see the following window, where you just type the name of the control you're looking for and it's immediately filtered. Once you select the component (if there's more than one matching the name) and press ENTER, the component is selected in the palette:

    enter image description here

    You will then write the event handler method for the OnPaint event of your TPaintBox component and do your drawing on the component's Canvas there:

    procedure TForm1.PaintBox1Paint(Sender: TObject);
    begin
      PaintBox1.Canvas.Brush.Color := clGreen;
      PaintBox1.Canvas.FillRect(PaintBox1.ClientRect);
    end;