3 Answers, 1 is accepted
The resize cursors are displayed through the native Cursor property of the resize handles of the ManipulationAdorner of the diagram. Basically, when you hover the resize handle (the small rectangle on the ManipulationAdorner's corner) its Cursor property is set to a cursor from the DiagramCursors class.
You can change the cursor of a resize handle by setting the Cursor property of the Rectangle that presents it when the mouse enters it. You can use the ChildrenOfTypeExtensions.ChildrenOfType<T>() method to get the handles. Another approach is to set the set the DiagramCursors.ResizeNWSE and DiagramCursors.ResizeNESW static properties before the InitializeComponent() method is called, but this will work only initially and runtime changes im tjos property won't be reflected in the UI.
When it comes to rotation of the cursor, as discussed in the forum post which you mentioned, I am afraid that there is not an easy approach for achieving this. Here are some suggestions which you can try on your side:
- Create several cursor files (.cur, .ico) and add them in your project. One for each angle at which you want to rotate the shape. Then on mouse enter of the resize handle (the Rectangle element) set its Cursor property to a particular cursor image based on the RotationAngle property of the SelectedItem of the diagram.
- Hide the default cursors and implement custom logic that displays a UIElement that draws a cursor and rotate it using LayoutTransform. You can find this approach demonstrated in the attached project.
Regards,
Martin
Telerik
[quote]Martin said:You can change the cursor of a resize handle by setting the Cursor property of the Rectangle that presents it when the mouse enters it. You can use the ChildrenOfTypeExtensions.ChildrenOfType<T>() method to get the handles. [/quote]
This works for mouseover, but once the user starts dragging the resize handle around the mouseover cursor is replaced by DiagramCursors value.
[quote]Martin said: Another approach is to set the set the DiagramCursors.ResizeNWSE and DiagramCursors.ResizeNESW static properties before the InitializeComponent() method is called, but this will work only initially and runtime changes im tjos property won't be reflected in the UI.[/quote]
As you have pointed out, this method does not work if we want to change cursors at runtime since setting the DiagramCursors static properties must be done before InitializeComponent.
I need to update cursors at runtime so neither of these approaches works for me. Am I out of luck?
In order to change the cursor when you are resizing diagram items you will need to set the cursor on few key places in the code. When the mouse enters the resize handle, when the mouse is down over the handle and when the resizing operation is starting. You can do that through the MouseLeftButtonDown and MouseEnter events of the resize handle, and also the StartResizing event of the ResizingService of RadDiagram.
You can set the Cursor property of the diagram in the event handlers of MouseLeftButtonDown and StartResizing. In the MouseEnter, you can set the Cursor of the resize handle.
void
resizeHandle_MouseLeftButtonDown(
object
sender, MouseButtonEventArgs e)
{
this
.diagram.Cursor = Cursors.Hand;
}
void
resizingService_StartResizing(
object
sender, CancelingManipulationEventArgs e)
{
this
.diagram.Cursor = Cursors.Hand;
}
void
resizeHandle_MouseEnter(
object
sender, MouseEventArgs e)
{
var handle = (Rectangle)sender;
handle.Cursor = Cursors.Hand;
}
Regards,
Martin
Telerik