From 97ebd6da3b7dfbbda35cb97e799dd12db7337966 Mon Sep 17 00:00:00 2001 From: Richard Moss Date: Sat, 24 Jan 2015 09:02:05 +0000 Subject: [PATCH] ImageBoxEx SetCursor Changes ImageBox.SetCursor to be protected virtual and no longer tries to apply cursor logic if the control is currently panning. --- .../ImageBoxEx.cs | 81 ++++++++++--------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/Cyotek.Windows.Forms.ImageBox.Demo/ImageBoxEx.cs b/Cyotek.Windows.Forms.ImageBox.Demo/ImageBoxEx.cs index 381c25b..205d61b 100644 --- a/Cyotek.Windows.Forms.ImageBox.Demo/ImageBoxEx.cs +++ b/Cyotek.Windows.Forms.ImageBox.Demo/ImageBoxEx.cs @@ -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)