Skip to content

Commit

Permalink
ImageBoxEx SetCursor
Browse files Browse the repository at this point in the history
Changes ImageBox.SetCursor to be protected virtual and no longer tries
to apply cursor logic if the control is currently panning.
  • Loading branch information
cyotek committed Jan 24, 2015
1 parent 6e14f59 commit 97ebd6d
Showing 1 changed file with 43 additions and 38 deletions.
81 changes: 43 additions & 38 deletions Cyotek.Windows.Forms.ImageBox.Demo/ImageBoxEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -758,54 +758,59 @@ private void ResetDrag()
this.DragOriginOffset = Point.Empty;
}

private void SetCursor(Point point)
protected virtual void SetCursor(Point point)
{
Cursor cursor;
// http://forums.cyotek.com/imagebox/cursor-issue-in-imageboxex/msg92/#msg92

if (this.IsSelecting)
if (!this.IsPanning)
{
cursor = Cursors.Default;
}
else
{
DragHandleAnchor handleAnchor;
Cursor cursor;

handleAnchor = this.IsResizing ? this.ResizeAnchor : this.HitTest(point);
if (handleAnchor != DragHandleAnchor.None && this.DragHandles[handleAnchor].Enabled)
if (this.IsSelecting)
{
switch (handleAnchor)
{
case DragHandleAnchor.TopLeft:
case DragHandleAnchor.BottomRight:
cursor = Cursors.SizeNWSE;
break;
case DragHandleAnchor.TopCenter:
case DragHandleAnchor.BottomCenter:
cursor = Cursors.SizeNS;
break;
case DragHandleAnchor.TopRight:
case DragHandleAnchor.BottomLeft:
cursor = Cursors.SizeNESW;
break;
case DragHandleAnchor.MiddleLeft:
case DragHandleAnchor.MiddleRight:
cursor = Cursors.SizeWE;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
else if (this.IsMoving || this.SelectionRegion.Contains(this.PointToImage(point)))
{
cursor = Cursors.SizeAll;
cursor = Cursors.Default;
}
else
{
cursor = Cursors.Default;
DragHandleAnchor handleAnchor;

handleAnchor = this.IsResizing ? this.ResizeAnchor : this.HitTest(point);
if (handleAnchor != DragHandleAnchor.None && this.DragHandles[handleAnchor].Enabled)
{
switch (handleAnchor)
{
case DragHandleAnchor.TopLeft:
case DragHandleAnchor.BottomRight:
cursor = Cursors.SizeNWSE;
break;
case DragHandleAnchor.TopCenter:
case DragHandleAnchor.BottomCenter:
cursor = Cursors.SizeNS;
break;
case DragHandleAnchor.TopRight:
case DragHandleAnchor.BottomLeft:
cursor = Cursors.SizeNESW;
break;
case DragHandleAnchor.MiddleLeft:
case DragHandleAnchor.MiddleRight:
cursor = Cursors.SizeWE;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
else if (this.IsMoving || this.SelectionRegion.Contains(this.PointToImage(point)))
{
cursor = Cursors.SizeAll;
}
else
{
cursor = Cursors.Default;
}
}
}

this.Cursor = cursor;
this.Cursor = cursor;
}
}

private void StartResize(DragHandleAnchor anchor)
Expand Down

0 comments on commit 97ebd6d

Please sign in to comment.