Recent

Author Topic: Draw on a component with canvas  (Read 3726 times)

mmxngg

  • New Member
  • *
  • Posts: 29
Draw on a component with canvas
« on: February 15, 2012, 10:53:03 am »
I want to draw a rectangle on a component (a scrollbox) for dinamically select (at runtime) other components inside it.

I have tried this :

Code: [Select]
{ 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 ?
Now i'm on Win7/32bits with Lazarus 1.0.4 FPC 2.6.0

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Draw on a component with canvas
« Reply #1 on: February 15, 2012, 12:17:18 pm »
How is DesignBuffer handled? You are creating new instance of TBitmap every time you save, are you freeing it properly after it is used to restore?

mmxngg

  • New Member
  • *
  • Posts: 29
Re: Draw on a component with canvas
« Reply #2 on: February 15, 2012, 07:32:08 pm »
OnMouseDown - Create and save
OnMouseMove - Restore and draw
OnMouseUp - Restore and free

All my issues are with TScrollbox....i will cut off it and replaced by custom component for making a scroll... :/
Now i'm on Win7/32bits with Lazarus 1.0.4 FPC 2.6.0

 

TinyPortal © 2005-2018