You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I intended to add a Pan feature, or an Auto-Scroll to the program.
The idea is pretty simple, if the user hold the mouse's middle button, the screen can automatically be scrolled vertically and horizontally according to the position of the cursor when start holding, and the current position of the mouse.
I failed terribly in implementing my code for hours of trying. If there's anybody reading this, could you please add this feature or maybe teach me how to implement it?
(I try to add some codes into Canvas.cs)
`
#region Hover Scroll:
bool isHoverScrollMode = false;
Point hoverScrollOriginLocation;
Timer hoverScrollTimer = new Timer();
int hoverScrollTimerInterval = 5;
int hoverScrollSpeed = 1;
private void Canvas_MouseDown(object sender, MouseEventArgs e)
{
if (HasDocument)
if (e.Button == MouseButtons.Middle)
SetActiveHoverScroll(e, true);
}
private void Canvas_MouseUp(object sender, MouseEventArgs e)
{
if (HasDocument)
if (e.Button == MouseButtons.Middle)
SetActiveHoverScroll(e, false);
}
private void SetActiveHoverScroll(MouseEventArgs e, bool isActive)
{
isHoverScrollMode = isActive;
if (isHoverScrollMode)
{
hoverScrollTimer.Start();
hoverScrollOriginLocation = e.Location;
hoverScrollTimer.Interval = hoverScrollTimerInterval;
hoverScrollTimer.Tick += (sender, eventArgs) => { ScrollWithHoverScroll(sender, e); } ;
}
else
{
hoverScrollTimer.Stop();
}
}
private void ScrollWithHoverScroll(object sender, MouseEventArgs e)
{
if (e.Location.X > hoverScrollOriginLocation.X)
{
ScrollHorizontally(-hoverScrollSpeed);
}
else if (e.Location.X < hoverScrollOriginLocation.X)
{
ScrollHorizontally(hoverScrollSpeed);
}
if (e.Location.Y > hoverScrollOriginLocation.Y)
{
ScrollEventArgs s = new ScrollEventArgs(ScrollEventType.SmallDecrement,hoverScrollSpeed, ScrollOrientation.VerticalScroll );
base.OnScroll(s);
}
else if (e.Location.Y < hoverScrollOriginLocation.Y)
{
ScrollEventArgs s = new ScrollEventArgs(ScrollEventType.SmallIncrement, hoverScrollSpeed, ScrollOrientation.VerticalScroll);
base.OnScroll(s);
}
//document_NeedsRedraw(sender, e);
UpdateDocumentOffset();
}
#endregion
`
The text was updated successfully, but these errors were encountered:
I intended to add a Pan feature, or an Auto-Scroll to the program.
The idea is pretty simple, if the user hold the mouse's middle button, the screen can automatically be scrolled vertically and horizontally according to the position of the cursor when start holding, and the current position of the mouse.
I failed terribly in implementing my code for hours of trying. If there's anybody reading this, could you please add this feature or maybe teach me how to implement it?
(I try to add some codes into Canvas.cs)
`
`
The text was updated successfully, but these errors were encountered: