Resize cursors

4 posts, 1 answers
  1. David
    David avatar
    2 posts
    Member since:
    Mar 2015

    Posted 28 Dec 2015 Link to this post

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

  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 31 Dec 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. David
    David avatar
    2 posts
    Member since:
    Mar 2015

    Posted 04 Jan in reply to Martin Link to this post

    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.

    This works for mouseover, but once the user starts dragging the resize handle around the mouseover cursor is replaced by DiagramCursors value.

    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.

    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?

  5. Answer
    Martin
    Admin
    Martin avatar
    1101 posts

    Posted 07 Jan Link to this post

    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
Back to Top