I put a paintbox in a scrollbox, having the same size as the scrollbox. When I then draw in the paintbox and beyond the size of the scrollbox, To get the whole drawing, I have to adapt the paintbox size (width and/or height) at runtime, which is OK.
However, when setting back the paintbox size to the scrollbox size before starting a next drawing, no longer produces a complete drawing. Instead, it only draws the surface of the scrollbox and then stretches that up to the actual drawing surface.
So, once a paintbox becomes larger than a scrollbox, it is not possible to start with an original surface.
The example below is code for a scrollbox+paintbox+button.
Attached is the complete example with alternative tries:
PaintboxExample.zip (7.3 KB)
Is there a proper way to adapt the size of a paintbox?
Kind regards,
Michel Huybrechts
Micriconsult BV
procedure TForm1.WebFormShow(Sender: TObject);
begin
v_CanPaint1 := False;
end;
procedure TForm1.WebButton1Click(Sender: TObject);
begin
v_CanPaint1 := True;
WebPaintBox1Paint(WebPaintBox1)
end;
procedure TForm1.WebPaintBox1Paint(Sender: TObject);
{
Works correctly, but only the first time. The next paint stretches the
visible part up to the calculated height???
}
begin { TForm1.WebPaintBox1Paint }
if v_CanPaint1
then
begin
{ Reset the height }
WebPaintBox1.Height := WebScrollBox1.Height;
WebPaintBox1.Canvas.Clear;
WebPaintBox1.Canvas.MoveTo(0, 0);
WebPaintBox1.Canvas.LineTo(150, 150);
WebPaintBox1.Canvas.MoveTo(100, 1000);
WebPaintBox1.Canvas.LineTo(100, 100);
WebPaintBox1.Canvas.TextOut(30, 10, 'Visible text');
WebPaintBox1.Canvas.TextOut(30, 500, 'Invisible text');
{ Set the height: does not work the second time. Drawing is stretched }
WebPaintBox1.Height := 1000
end
end { TForm1.WebPaintBox1Paint };