Customizing the Paintbox Font Calls OnPaint

I need to write text in paintbox, and I do this in the OnPaint event. When I set fontsize in a method twice, the OnPaint event is raised repeatedly.

To verify this, try the following:

  • Create a New VCL Forms Application
  • Place the printable box on the form
  • Put the following code in the OnPaint event:
procedure TForm1.PaintBox1Paint (Sender: TObject);
begin
  PaintBox1.Canvas.MoveTo (random (PaintBox1.Width), random (PaintBox1.Height));
  PaintBox1.Canvas.LineTo (random (PaintBox1.Width), random (PaintBox1.Height));

  PaintBox1.Font.Size: = 10; 
  PaintBox1.Font.Size: = 12; 
end;

When you start the application, you will see a line "jumping" around in the paintbox. However, if you delete one or both lines that specify the font, you will see one fixed line.

, , ?

+3
1

PaintBox1.Canvas.Font.Size PaintBox1.Font.Size, .

: , , . , , , .

+7

Source: https://habr.com/ru/post/1753169/


All Articles