Overriding Cursors

Questions, comments and suggestions concerning VintaSoft PDF .NET Plug-in.

Moderator: Alex

Post Reply
IntegraMike
Posts: 56
Joined: Mon Dec 02, 2019 11:19 pm

Overriding Cursors

Post by IntegraMike »

Hi, I'm looking to overwrite the cursors for the annotation tool for specific annotation types (ex. Replace the normal cursor and action cursor for the PdfAnnotationTool to reflect the annotation that will be created by the tool is an ink annotation, etc.). I can get the icon replaced, but for some reason it doesn't always get reflected in the viewer. Also, updating the action cursor doesn't seem to be doing anything (it always goes back to the cross).

So far as I can tell, the cursor being displayed is the ImageViewer's cursor property, but that seems to be set in the background by active tools etc. Is there a way for me to force the viewer to take the cursor off of a specific tool or otherwise lock the ImageViewer's cursor image?

Of note, I have tried overriding the cursor properties in the ImageViewer, PdfAnnotationTool, and CompositeVisualTool and I that gets things close (specifically the ImageViewer works the best) however it dramatically slows down drawing ink annotations (I assume because it's constantly flipping back and forth between cursors under the hood somewhere). It also sometimes keeps my cursor around even when I do the following:

Code: Select all

public class MyImageViewer : ImageViewer
{
	private Cursor _lockCursor = null;

	public void LockCursor(Cursor lockCursor)
	{
		_lockCursor = lockCursor;
	}

	public override Cursor Cursor
	{
		get
		{
			if (_lockCursor != null)
			{
				return _lockCursor;
			}
			else
			{
				return base.Cursor;
			}
		}

		set => base.Cursor = value;
	}
}
And then when I want my cursor to override everything I call LockCursor(newCursor) and when I want it to go back to normal operation I call LockCursor(null). Sometimes I'll switch to a different tool and the previously locked cursor comes back from somewhere I haven't been able to find.

Thanks!
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Overriding Cursors

Post by Alex »

Hi Mike,

It is bad idea to lock cursor of image viewer because there is a lot of objects, which change cursor in image viewer.

Here is "small list" of object, which can change cursor in image viewer: Please change cursor in all used objects instead of "locking" cursor of image viewer.

Best regards, Alexander
IntegraMike
Posts: 56
Joined: Mon Dec 02, 2019 11:19 pm

Re: Overriding Cursors

Post by IntegraMike »

That was actually what I tried to do first, but there's something going on in the background that is occasionally bringing back cursors that aren't valid for the tool (especially when hovering over locked annotations for some reason). I've gone back to that and by adding the hack of in the mouse move event for the annotation tool setting the ImageViewer's cursor to the cursor of the annotation viewer. Currently we don't have custom action cursors or this wouldn't work, but it seems to get things going until I have time to go back and fix this the right way. I think there's probably something going awry in the SetCursor/RestoreCursor methods that I assume are being used internally when the cursor is being updated based on a tool, so maybe overriding those will do it, but that's just a guess.

Thanks for the help!
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Overriding Cursors

Post by Alex »

Thank you for information.

If you cannot solve problem by yourself, please send us (to support@vintasoft.com) a small project, which allows to reproduce the problem, and we will try to improve your code.

Best regards, Alexander
Post Reply