Search code examples
delphifiremonkey

How to use FireMonkey TCanvas.DrawXXX methods?


I try to create a form with a custom visualisation, but I can't get the simplest drawing methods of TCanvas to work. In the following example, I can see only the filled rectangle, but no line and no arc:

procedure TEditorPanel.FormPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
var
  center, radius: TPointF;
  rect: TRectF;
begin
  with Canvas do
  begin
    Fill.Color := TAlphaColors.White;
    FillRect(RectF(0, 0, Width, Height), 0, 0, AllCorners, 1);

    center := PointF(200, 200);
    radius := PointF(40, 40);

    Stroke.Color := TAlphaColors.Red;
    Fill.Color := TAlphaColors.Blue;
    DrawLine(center, radius, 1);
    DrawArc(center, radius, 0, 90, 1);

    rect := RectF(10, 10, 100, 100);
    FillRect(rect, 0, 0, AllCorners, 100);
  end;
end;

What am I missing?


Solution

  • if you are using Delphi 10.1 or above You should set Stroke.Kind to TBrushKind.Solid to get lines appear, default value in None :

    var
      center, radius: TPointF;
      rect: TRectF;
    begin
      with Canvas do
      begin
        Fill.Color := TAlphaColors.White;
        FillRect(RectF(0, 0, Width, Height), 0, 0, AllCorners, 1);
    
        center := PointF(200, 200);
        radius := PointF(40, 40);
    
        Stroke.Kind := TBrushKind.Solid;
        Stroke.Color := TAlphaColors.Red;
        Fill.Color := TAlphaColors.Blue;
        DrawLine(center, radius, 1);
        DrawArc(center, radius, 0, 90, 1);
    
        rect := RectF(10, 10, 100, 100);
        FillRect(rect, 0, 0, AllCorners, 100);
      end;