I want to draw a rectangle on a component (a scrollbox) for dinamically select (at runtime) other components inside it.
I have tried this :
{ Save the canvas }
DesignBuffer := TBitmap.Create;
DesignBuffer.LoadFromDevice(ScrollBoxDesign.Canvas.Handle);
DesignArea.Top := ScrollBoxDesign.VertScrollBar.Position;
DesignArea.Bottom := DesignArea.Top + ScrollBoxDesign.Height - 1;
DesignArea.Left := ScrollBoxDesign.HorzScrollBar.Position;
DesignArea.Right := DesignArea.Left + ScrollBoxDesign.Width - 1;
{ Draw something (Selection are inside bounds) }
ScrollBoxDesign.Canvas.Rectangle(SelectionLeft, SelectionTop, SelectionRight, SelectionBottom);
{ Restore the canvas }
ScrollBoxDesign.Canvas.CopyRect(DesignArea, DesignBuffer.Canvas, DesignArea);
Works well when scrollbox don't have scrolling else i get SIGSEGV error when i try to restore the canvas. What's wrong ?