Solved

Automatic scrolling when dragging over TScrollBox (Delphi)

Posted on 2007-11-29
3
987 Views
Last Modified: 2010-04-21
In my Delphi application I have a TScrollBox with only the vertical scroll bar enabled.

When the scroll box is too small for its contents then the vertical scroll box appears automatically - that's fine.

I would like the scrollbox to automatically scroll up and down as necessary when the user drags an object over it (so they can find the right place to drop it).

Does anyone know how to achieve this?
0
Comment
Question by:plumothy
  • 2
3 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 20372282
try this:

procedure TForm1.ScrollBox1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
var calcX, calcY: Integer;
begin
  //calcX, calcY calculate how you want it to scroll
  ScrollBox1.ScrollBy(calcX, calcY);
end;


ziolko.
0
 
LVL 21

Accepted Solution

by:
ziolko earned 500 total points
ID: 20372548
...or even bettetr use ScrollBox.VertScrollBar.Position something like:

procedure TForm1.ScrollBox1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := Source is TTreeView;
  if Y < 15 then
    ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position - 8
  else if Y > ScrollBox1.Height  - 15 then
    ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position + 8;
end;

ziolko.
0
 

Author Closing Comment

by:plumothy
ID: 31411609
Perfect, thanks
0

Featured Post

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!

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

13 Experts available now in Live!

Get 1:1 Help Now