Reputation: 377
In my application, there are two instances where I would like to use a non-default cursor.
One is on a panel which the user may "draw" on using the mouse. I would like to change the cursor from the default mouse to a pen or paintbrush. I would like to get an image from online, convert it to the appropriate filetype and use it as my cursor for the panel.
The other instance is when an image is added to a rich text box. I would like to add the correct "resize" arrows so that when the user hovers the mouse over one of the small black boxes, the cursor changes to the double arrow (like in other programs).
How easy is this to achieve?
I don't have a clue where to start when it comes to implementing the resize arrows, as there isn't always an image in the rich text box (only when the application is being debugged or used).
Upvotes: 0
Views: 1138
Reputation: 244692
All of the controls in WinForms have a Cursor
property, since they all inherit from System.Windows.Forms.Control
. Whatever cursor you assign to this property will be displayed automatically when the mouse pointer is over that control.
This is an ambient property, which means that it automatically inherits its value from its parent (for example, a Button control would automatically use the same cursor as its parent form) unless it is explicitly set otherwise.
So to change the cursor displayed over a certain control, all you need to do is set that control object's Cursor
property. The framework will take care of the rest.
Upvotes: 0
Reputation: 163
Even better, use the MouseHover
event and add a new handler to change the cursor when it is called.
Upvotes: 0
Reputation: 163
There is actually a cursor option for winforms in the properties tab, you could change the cursor whenever the Cursor.Position
is equal to the item's position.
Upvotes: 1