Skip to content
This repository has been archived by the owner on Aug 2, 2019. It is now read-only.

Add PanningEnabled property so consumers can disable panning #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions PdfiumViewer/PanningZoomingScrollControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ static PanningZoomingScrollControl()

public event EventHandler ZoomChanged;

/// <summary>
/// If true, cursor will be a hand and the mouse can be used to pan
/// within the document. If false, cursor will be an arrow and
/// mouse operations can be defined by consumers of the control.
/// </summary>
[DefaultValue(true)]
public bool PanningEnabled = true;

private bool ShouldPan
{
get { return _canPan && PanningEnabled; }
}

protected virtual void OnZoomChanged(EventArgs e)
{
var ev = ZoomChanged;
Expand Down Expand Up @@ -226,7 +239,7 @@ protected override bool IsInputKey(Keys keyData)

protected override void OnSetCursor(SetCursorEventArgs e)
{
if (_canPan && e.HitTest == HitTest.Client)
if (ShouldPan && e.HitTest == HitTest.Client)
e.Cursor = PanCursor;

base.OnSetCursor(e);
Expand All @@ -243,7 +256,7 @@ protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);

if (e.Button != MouseButtons.Left || !_canPan)
if (e.Button != MouseButtons.Left || !ShouldPan)
return;

Capture = true;
Expand All @@ -255,7 +268,7 @@ protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);

if (!Capture)
if (!Capture || !ShouldPan)
return;

var offset = new Point(e.Location.X - _dragStart.X, e.Location.Y - _dragStart.Y);
Expand Down