Cursor issue in ImageBoxEx

Started by wmjordan, November 29, 2014, 09:52:51 AM

Previous topic - Next topic

wmjordan

The line "cursor = Cursors.Default;" before "this.Cursor = cursor;" in SetCursor should be changed to "cursor = this.IsPanning ? this.Cursor : Cursors.Default;". Otherwise, when we turn on panning and use this dragging enabled control, the panning cursor would be changed to Default.

Also, I suggest that leaving the SetCursor method to be overridable or interceptable by providing a callback to be executeed in the SetCursor method.
I am now writing an image viewer which enables the user to click somewhere on the image to perform some actions. I would love to set the cursor to some shape when the user hovers his mouse on a certain regions. The SetCursor method keep turning the cursor to Default which makes the cursor flickering between Default and my own style.

wmjordan

#1
Today I changed the SetCursor method from private to protected virtual.
protected virtual void SetCursor(Point point)

Afterward, in the subclass of the ImageBoxEx, I wrote the following code and it was working fine. The cursor no longer flickered when we panned the image, and it changed to Hand when it was moved to some places defined in my program.

protected override void SetCursor (DrawingPoint point) {
if (IsPanning) {
return;
}
if (!IsResizing || !IsSelecting) {
var p = CustomCheckForCursorPosition (point.X, point.Y);
if (p.Clickable) {
this.Cursor = Cursors.Hand;
return;
}
}
base.SetCursor (point);
}

Richard Moss

Many thanks for both the bug report and the contribution! I'll make sure both of these are in the next update to the control.

Regards;
Richard Moss

wmjordan

Thank you very much for looking into the problem!