Solved

Auto Scroll

Posted on 1999-01-03
11
384 Views
Last Modified: 2010-04-04
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
Comment
Question by:ItsMe
  • 6
  • 5
11 Comments
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
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
 

Author Comment

by:ItsMe
Comment Utility
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
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
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
 

Author Comment

by:ItsMe
Comment Utility
The example from Borland (Graphex) is the same like mine.
0
 

Author Comment

by:ItsMe
Comment Utility
... the same principle ...
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:ItsMe
Comment Utility
Help !

0
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
Sorry...
I still haven't installed Delphi 4 (Graphex?). Post whatever you have, and explain what doesn't work. Sorry...
0
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
Send it please to me <bosism@netvision.net.il>
0
 

Author Comment

by:ItsMe
Comment Utility
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
 
LVL 3

Accepted Solution

by:
Matvey earned 20 total points
Comment Utility
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
 

Author Comment

by:ItsMe
Comment Utility
Thank you ! It works very well.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now