1
votes

I simply can't figure out what I'm doing wrong when trying to paint a control.

I've tried using TCanvas.BeginScene()/TCanvas.EndScene(), tried painting in other methods (for example main form OnPaint()).
I've tried TControl.InvalidateRect().
I get nothing.

Here's what I have in my test app:

type
  TTestControl = class(TControl)
  protected
    procedure Paint; override;
  end;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    fTestControl: TTestControl;
  end;

procedure TTestControl.Paint;
begin
  Canvas.Fill.Color := TColorRec.Blueviolet;
  Canvas.FillEllipse(ClipRect, AbsoluteOpacity);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  fTestControl := TTestControl.Create(Self);
  fTestControl.Parent := Self;
  fTestControl.Align  := TAlignLayout.Client;
end;

It ought to be enough, according to what's online.
Any suggestions?

2

2 Answers

2
votes

The Canvas.Fill.Color is a TAlphaColor.

Change the line

  Canvas.Fill.Color := TColorRec.Blueviolet;

to

  Canvas.Fill.Color := TAlphaColors.Blueviolet;
0
votes

Your Paint methods should be like this:

procedure TTestControl.Paint;
begin
  inherited;
  Canvas.BeginScene;
  Canvas.Fill.Color := claBlueviolet;
  Canvas.FillEllipse(ClipRect, AbsoluteOpacity);
  Canvas.EndScene;
end;

I, also, think you should override the DoPaint method of TControl and not the Paint.