Rightclick events on connection in RadDiagram

1 Answer 51 Views
Diagram, DiagramRibbonBar, DiagramToolBox
Farid
Top achievements
Rank 2
Farid asked on 06 Oct 2023, 06:38 PM
HI.
I trying to create a Connection in RadDiagram  With VB.net
My use case is adding a handler to detect mouse right click on the connection. Although the following code does not give an error, it does not work either.

Blow is my simple test code.

Imports Telerik.WinControls
Imports Telerik.WinControls.UI

Public Class RadForm1

    Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim con As New RadDiagramConnection
        con.Name = "Telerik_Connection"
        con.StartPoint = New Point(10, 10)
        con.EndPoint = New Point(100, 100)
        con.StrokeThickness = 5
        con.BackColor = Color.Blue
        AddHandler con.MouseClick, AddressOf Con_click

    End Sub

    Private Sub Con_click(ByVal sender As Object, ByVal e As MouseEventArgs)
        If e.Button = MouseButtons.Right Then
            Me.Text = sender.name
        End If
    End Sub
End Class


1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 10 Oct 2023, 07:53 AM

Hi Farid,

Thank you for the provided code snippet.

You will need to handle the MouseClick event of the RadDiagram. In the event handler, you can check if the Right mouse button is clicked and check if the mouse location is in the bounds of the connection. The following code snippet will better demonstrate what I have in mind.

Sub New()
    InitializeComponent()
    AddHandler Me.RadDiagram1.MouseClick, AddressOf MouseClickEventHandler
End Sub

Private Sub MouseClickEventHandler(sender As Object, e As MouseEventArgs)
    If e.Button = MouseButtons.Right Then
        For Each c As RadDiagramConnection In Me.RadDiagram1.Connections
            If c.HitTest(e.Location) Then
                RadMessageBox.Show("Connection Clicked")
            End If
        Next
    End If
End Sub

I hope that this approach will work for you.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Diagram, DiagramRibbonBar, DiagramToolBox
Asked by
Farid
Top achievements
Rank 2
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or