Hello all,
I have a UserControl that is in a Panel. The Panel's AutoScroll is
set to true. When the user drags data over the Panel and hits the
edges, I want the control to scroll.
I've managed to get this all to work. But I have a few questions:
- Is there a standard distance from the edge of the window that the
mouse should be before scrolling starts?
- How much does one scroll each instance? I've tuned mine to match the
speed of the machine I'm doing development work on... Obviously this
may not work for others.
And one technical question. To do the scrolling I adjust the
AutoScrollPosition property while handling the OnDragOver event. If I
do this every time the OnDragOver event is fired, my scroll bars move,
but nothing is re-drawn (until the scroll bars go as far as they can).
On the other hand, if I update the auto scroll position every other
time OnDragOver is fired, then everything works as expected: the scroll
bars move and the panel is updated. This seems odd, and I find no
details on this in the documentation or in a search of the newsgroups.
One other question. What is DragDropEeffects.Scroll used for? Is
there any point to it? Or is it just there in case you want to change
cursors.
Finally -- I'm doing my scrolling in OnDragOver. Should I do it in
GiveFeedback instead? I'm a little unclear how the framework expects me
to seperate the tasks (currently, since I have no special cursors, I do
implement GiveFeedback).
Cheers,
Gordon.
Point mouseCurrent = PointToClient(new Point (drgevent.X, drgevent.Y));
///
/// Is it time to scroll (if possible)? Skip every other call to give
/// the rest of the update framework a chance to catch up.
///
//// _lastDidIt switches from true to false on each call, it is a
method variable.
int dragboarder = 20;
int dragscrolldist = 5;
if (mouseCurrent.Y > Height-dragboarder)
{
if (_lastDidIt)
AutoScrollPosition = new Point (-AutoScrollPosition.X,
-AutoScrollPosition.Y+dragscrolldist);
}
if (mouseCurrent.Y < dragboarder)
{
if (_lastDidIt)
AutoScrollPosition = new Point (-AutoScrollPosition.X,
-AutoScrollPosition.Y-dragscrolldist);
}
if (mouseCurrent.X > Width-dragboarder)
{
if (_lastDidIt)
AutoScrollPosition = new Point
(-AutoScrollPosition.X+dragscrolldist,
-AutoScrollPosition.Y);
}
if (mouseCurrent.X < dragboarder)
{
if (_lastDidIt)
AutoScrollPosition = new Point
(-AutoScrollPosition.X-dragscrolldist,
-AutoScrollPosition.Y);
}
_lastDidIt = !_lastDidIt;
///
/// Make sure everything is re-drawn.
///
Invalidate();