Author Topic: Problem with big canvas on ScrollBox  (Read 433 times)


  • Full Member
  • ***
  • Posts: 125
Problem with big canvas on ScrollBox
« on: March 01, 2024, 03:08:48 pm »

I put images onto a ScrollBox and I would like copy pieces from those onto an other image with CopyRect() function. But when I click on the edge of these images on the ScrollBox, then the small image contains the pieces of scrollbar instead the other parts of the image, which sticking out from ScrollBox.
Then, when I scroll away the image, CopyRect() produces white rectangles instead of right image. So, how big is the canvas of an image? Is it equal only with its visible area? Or how can I access to its whole parts when I scroll it back and forth?
I create images with this procedure:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.buttonImageAdClick(Sender: TObject);
  2. begin
  3.    if (imageOpener.Execute) and (sourcetiles<255) then
  4.    begin
  5.      tileimage[sourcetiles+1]:=TImage.Create(Self);
  6.      tileimage[sourcetiles+1].Parent:=placeofTiles;
  7.      tileimage[sourcetiles+1].Autosize:=true;
  8.      tileimage[sourcetiles+1].Transparent:=true;
  9.      tileimage[sourcetiles+1].Picture.LoadFromFile(imageOpener.FileName);
  10.      tileimage[sourcetiles+1].OnMouseUp:=@clickontile;
  11.      tileimage[sourcetiles+1].Left:=0;
  12.      if sourcetiles=0 then
  13.      begin
  14.         tileimage[sourcetiles+1].Top:=0;
  15.         actualtile:=1;
  16.      end
  17.      else
  18.         tileimage[sourcetiles+1].Top:=tileimage[sourcetiles].Top+tileimage[sourcetiles].height+2;
  19.      inc(sourcetiles);
  20.    end;
  21. end;
and this is where I copy small images from the tiles:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.clickontile(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. var i: byte;
  4. begin
  5.      for i:=0 to sourcetiles-1 do
  6.      begin
  7.        if (X>=tileimage[i+1].Left) and (X<=tileimage[i+1].Left+tileimage[i+1].width) and (Y>=tileimage[i+1].Top) and (Y<=tileimage[i+1].Top+tileimage[i+1].height) then
  8.        begin
  9.             if copytileexists=false then
  10.             begin
  11.               copytile:=TImage.Create(Self);
  12.               copytile.Parent:=self;
  13.               copytile.Left:=X;//+tilePlace.HorzScrollbar.position;
  14.               copytile.Top:=Y;//+tilePlace.VertScrollbar.position;
  15.               copytile.width:=tilewidth;
  16.               copytile.height:=tileheight;
  17.             end;
  18.             copytile.canvas.copyrect(Rect(0,0,tilewidth,tileheight),tileimage[i+1].canvas,Rect(X,Y,X+tilewidth,Y+tileheight));
  19.             copytileexists:=true;
  20.             Break;
  21.        end;
  22.      end;
  23. end;
« Last Edit: March 01, 2024, 03:10:35 pm by Tomi »


  • Full Member
  • ***
  • Posts: 125
Re: Problem with big canvas on ScrollBox
« Reply #1 on: March 02, 2024, 03:34:55 pm »
Well, carefully read about these problem it seems that it is not easy to access to offscreen part of the images.
But then how store the OS or Lazarus itself the content of whole image? Since I can see that when I scroll away the image in the ScrollBox.


TinyPortal © 2005-2018