1. what is the diff between Timage and TPaintBox ?
TImage draws an image, so you can draw to this buffer image at any time and it will be shown to the screen when required. TImage is not made for fast changing graphics, but if your graphics change slowly it should be fine.
TPaintBox is just a pre-made TCustomControl, so you cannot draw to it outside the OnPaint event.
In general read:
http://wiki.lazarus.freepascal.org/Developing_with_Graphics2. Id I do some line drawing on Timage canvas following this example:
http://123codegenerator.blogspot.com/2010/04/click-and-drag-mouse-to-draw-line-using.html
Each form resize or scroll (as timage is inside scrollbox) erases all lines. How to handle that ?
As very often with Delphi, the code you posted is Windows only. Never draw to a visual control outside the OnPaint event.
Instead you have multiple possible solutions:
1> Draw to a TBitmap instead. In the OnPaint draw this TBitmap to the form Canvas. Call Invalidate when you modified the bitmap to request a form redraw.
2> Use a TImage which does the same as option 1 internally
3> A more complex one. Use fpvectorial for example to handle the list of all lines and other vectors of the image and then use fpvectorial too to render them
All of those will also be safe in case of resize
3. Following example from above link, scrolling image inside scroll box, proc:
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Drawing := true;
StartX := x;
//...
The coordinates are not picked up correctly any more after scroll.
How to handle that ?
How exactly are they not correct?
You could also try Mouse.CursorPos + ScreenToClient()