This is a migrated thread and some comments may be shown as answers.

Resize cursors

3 Answers 576 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 28 Dec 2015, 10:11 PM

This post makes it sound like there is no way to change the resize cursors for diagram shapes ... is this still the case?

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 31 Dec 2015, 02:32 PM
Hi David,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
David
Top achievements
Rank 1
answered on 04 Jan 2016, 09:28 PM

[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?

0
Accepted
Martin Ivanov
Telerik team
answered on 07 Jan 2016, 12:19 PM
Hi David,

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;
}
I updated the project from my last reply to demonstrate this approach. Please give it a try and let me know if it helps.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Diagram
Asked by
David
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
David
Top achievements
Rank 1
Share this question
or