How to Change the Cursor in Xamarin.Mac

AllanChin.6924AllanChin.6924 USUniversity ✭✭✭

Does anybody know how to change the mouse cursor programmatically in a Xamarin.Mac app? I don't need anything fancy. I just want to be able to change the cursor to some of the pre-defined NSCursors say on MouseDown and MouseUp events, for example.

Thanks

Best Answers

Answers

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    Something like this:

    http://stackoverflow.com/questions/2925580/cocoa-change-cursor-when-its-over-an-nsbutton

    A quick check suggests all of the needed selectors are already bound.

  • AllanChin.6924AllanChin.6924 USUniversity ✭✭✭

    Thanks Chris. I seen a lot of Cocoa posts but...

    Calling an NSView's AddCursorRect() doesn't seem to do anything. And an NSView doesn't seem to have a SetCursor() method.

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    Are you subclassing your view and calling it with resetCursorRects's override as noted here?

    http://stackoverflow.com/a/13266513/36782

    Could you post your code?

  • AllanChin.6924AllanChin.6924 USUniversity ✭✭✭

    Ok Chris, according to that article the goal was to change the cursor when the cursor is over a button. I worked up a simple app which just contains a Box whose class I specified as MyBox which is derived from an NSBox. In MyBox I overrode ResetCursorRects() and in it called AddCursorRect(). It doesn't appear the ResetCursorRects() method is ever invoked.

    That article also says that call to SetCursor() should be made somewhere. Not only am I unclear as to where such a call should be made, as I said before, NSView does not even expose a SetCursor() method.

    I've attached my simple Mac app.

    Thanks.

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    I don't see said attachment. Maybe it got dropped on the floor somewhere?

  • AllanChin.6924AllanChin.6924 USUniversity ✭✭✭

    Whoops! Picked it up and attached it this time.

  • AllanChin.6924AllanChin.6924 USUniversity ✭✭✭

    Sorry about that Chris. I guess it was still too early for me. Yes, your changes work as advertised. So actually, what I'd like to do is change the cursor during mouse Down, Up and Drag events in a GestureRecognizer when resizing a custom box. ResetCursorRects() is only ever called once and magically handles hover nicely, but it seems like I need some sort of SetCursor() method which doesn't exist. What would you recommend to achieve what I'm looking for.

    Thanks.

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    I think calling ResetCursorRects yourself in those events is kosher and fine (from my very limited skimming of the docs) and letting your logic there (maybe with an enum of what state you want).

Sign In or Register to comment.