[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

Auto Scroll

Hi,
I'm using a scrollbox with a TImage component. How do I make the scrollbox autoscroll to the right direction, when I arrive the Border of it ? I want that the point you are editing of the image is visible while editing. E.g. the user of my program wants to draw a rectangle. The problem is that he cannot see the size of it, when the image size is bigger than the size of the scroll box.
0
ItsMe
Asked:
ItsMe
  • 6
  • 5
1 Solution
 
MatveyCommented:
Just check the mouse events and coordinates, and calculate the delta X and Y to scroll.
You can also find various image components on the Delphi pages that have built in scrolling...
0
 
ItsMeAuthor Commented:
OK, I know the mouse Coords (the position on the image) but
how do I know if they are in the visible area of the scrollbox ?
The user klicks (holds) and pulls the mouse to draw a rectangle circle etc.
0
 
MatveyCommented:
I think it's best to check if the cursor reached the edges and going beyond them. It's hard to imagine the thing you've set up here - can you tell more, or even post the unit?
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
ItsMeAuthor Commented:
The example from Borland (Graphex) is the same like mine.
0
 
ItsMeAuthor Commented:
... the same principle ...
0
 
ItsMeAuthor Commented:
Help !

0
 
MatveyCommented:
Sorry...
I still haven't installed Delphi 4 (Graphex?). Post whatever you have, and explain what doesn't work. Sorry...
0
 
MatveyCommented:
Send it please to me <bosism@netvision.net.il>
0
 
ItsMeAuthor Commented:
Graphex is included in Delphi 3 in the Demos\Doc\Graphex
directory. Graphex is an paint example. My problem is that
when I want to draw e.g. a  rectangle which becomes bigger
than the visible part of the image the scrollbox doesn't
scroll. I need to know how I can make the scrollbox scroll
when I arrive one of her edges/borders.
0
 
MatveyCommented:
Ahm... teehee, I have never seen this example! I guess you helped me discover something new too :)

OK. There are two methods to implement scrolling the drawing point into view. They are only different visually: one is

________________________________________________________________
procedure TForm1.ScrollPointInView(p: TPoint);
begin
  with scrollbox1 do begin
    with HorzScrollBar do
           if (p.x < Position) then Position := p.x
      else if (p.x > position + clientwidth) then Position := p.x - clientwidth;
    with VertScrollBar do
           if (Position > p.y) then Position := p.y
      else if (p.y > position + clientheight) then Position := p.y - clientheight;
  end;
end;

...............................

procedure TForm1.DrawShape(TopLeft, BottomRight: TPoint; AMode: TPenMode);
begin

  ScrollPointInView(BottomRight);

..................
end;
________________________________________________________________

Another method involves a timer, and the image is scrolled smoothly, incrementing the position by one (just a different effect).

Good luck and a happy new year!
--Matvey
0
 
ItsMeAuthor Commented:
Thank you ! It works very well.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now