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

MouseEnter MouseLeave events on Shapes in RadDiagram

2 Answers 158 Views
Diagram, DiagramRibbonBar, DiagramToolBox
This is a migrated thread and some comments may be shown as answers.
Milan
Top achievements
Rank 1
Milan asked on 11 Dec 2020, 08:43 AM

Hi,

Am trying to do the simplest of things in winforms/vb using the RadDiagram .. 

My use case is simply changing the color of a shape when the mouse enters it and back again when it leaves it. 

I have been experimenting with the events and their behaviors and cannot explain/figure out the following :

- mouse leave event fires correctly on the boundary of the shape (works as expected)

- mouse enter event fires only when the shape is selected and when touching the connector borders (the four default ones - up/down/left/right). the mouse changes to resize cursor when touching the four corner connectors

Below is my simple test code - 

Imports System.Globalization
Imports System.Math
Imports System.Drawing.Drawing2D
Imports System.Drawing.Color
Imports Telerik.Windows
Imports Telerik.Windows.Diagrams.Core
Imports Telerik.WinControls.UI
Imports Telerik.WinControls.UI.Diagrams
 
Public Class RadForm1
    Public Sub New()
 
        ' This call is required by the designer.
        InitializeComponent()
 
        ' Add any initialization after the InitializeComponent() call.
 
    End Sub
 
    Private Sub NewItemToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewItemToolStripMenuItem.Click
        Dim shape As LayoutShape = New LayoutShape()
        RadDiagram1.AddShape(shape)
    End Sub
 
 
    Private Sub RadDiagram1_ShapeClicked(sender As Object, e As ShapeRoutedEventArgs) Handles RadDiagram1.ShapeClicked
        Dim shape As LayoutShape = TryCast(e.Shape, LayoutShape)
 
        If (shape IsNot Nothing) Then
            shape.BackColor = Green ' reset
        End If
    End Sub
 
 
End Class
 
Public Class LayoutShape
    Inherits RadDiagramShape
 
    Public Sub New()
        IsEditable = False
        Shape = New Telerik.WinControls.RoundRectShape(5)
        AutoSize = False
        BorderBrush = New System.Drawing.SolidBrush(System.Drawing.Color.Red)
        ShouldHandleMouseInput = True
        SetBounds(0, 0, 100, 25)
        BackColor = Green
        Position = New Point(100, 100)
        IsEditable = False
        AutoToolTip = False
        NotifyParentOnMouseInput = True
 
    End Sub
 
 
    Public Sub LayoutShape_MouseLeave(sender As Object, e As EventArgs) Handles Me.MouseLeave
        Dim shape As LayoutShape = TryCast(sender, LayoutShape)
 
        shape.BackColor = Blue
    End Sub
 
    Private Sub LayoutShape_MouseEnter(sender As Object, e As EventArgs) Handles Me.MouseEnter
        Dim shape As LayoutShape = TryCast(sender, LayoutShape)
 
        shape.BackColor = Yellow
    End Sub
 
End Class

2 Answers, 1 is accepted

Sort by
1
Nadya | Tech Support Engineer
Telerik team
answered on 15 Dec 2020, 02:33 PM

Hello, Milan,

Thank you for the provided code snippet. 

Note, there is a DiagramShapeElement within RadDiagramShape which is responsible for customizing the shape like draw fill, set shape, borders, etc. This is why I would recommend you to handle the MouseLeave and MouseEnter events on this DiagramShapeElement in order to achieve the desired look. Please refer to the following code snippet:

 Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        Dim shape As LayoutShape = New LayoutShape()
        RadDiagram1.AddShape(shape)
        AddHandler shape.DiagramShapeElement.MouseEnter, AddressOf shape_MouseEnter
        AddHandler shape.DiagramShapeElement.MouseLeave, AddressOf shape_MouseLeave
        AddHandler Me.RadDiagram1.ShapeClicked, AddressOf RadDiagram1_ShapeClicked
    End Sub

    Private Sub shape_MouseLeave(sender As Object, e As EventArgs)
        Dim shape As LightVisualElement = TryCast(sender, LightVisualElement)
        shape.BackColor = System.Drawing.Color.Blue
    End Sub

    Private Sub shape_MouseEnter(sender As Object, e As EventArgs)
        Dim shape As LightVisualElement = TryCast(sender, LightVisualElement)
        shape.BackColor = System.Drawing.Color.Yellow
    End Sub

    Private Sub RadDiagram1_ShapeClicked(sender As Object, e As ShapeRoutedEventArgs)
        Dim shape As LayoutShape = TryCast(e.Shape, LayoutShape)
        If (shape IsNot Nothing) Then
            shape.BackColor = System.Drawing.Color.Green
        End If
    End Sub
End Class

MouseEnter:

MouseLeave:

ShapeClicked:

I hope this information helps. Should you have other questions please let me know.

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Milan
Top achievements
Rank 1
answered on 15 Dec 2020, 02:59 PM
Thank you Nadya .. That worked ! Suspected it was something basic :-} ..
Tags
Diagram, DiagramRibbonBar, DiagramToolBox
Asked by
Milan
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Milan
Top achievements
Rank 1
Share this question
or