Auto connect

I have a custom connector in the Palette. The custom connector can be dragged and placed on the diagram sheet. Then, I drag each end to other nodes to connect.

Am just asking if the following is possible:

I press on the custom connector in the palette. Then i move the mouse (with out the custom connector) to the diagram area. When i press on a node, it detects the node and automatically connects to it. The connector stays active until i find an other node to connect. When I click on the second node, the connection is created automatically.

Is this possible?
Iam vb net3.5 user

8 Replies

NG Naganathan Ganesh Babu Syncfusion Team March 2, 2018 08:32 AM UTC

Hi Allen, 
 
We have created a sample to achieve your requirement. we suggest you to use PaletteGroupBar’s NodeSelected event to activate the connector tool to achieve your requirement. please refer to the below code example and sample. 
 
Code example: 
 
[VB] 
 
AddHandler paletteGroupBar1.NodeSelected, AddressOf paletteGroupBar1_NodeSelected 
Private Sub paletteGroupBar1_NodeSelected(ByVal sender As Object, ByVal evtArgs As NodeEventArgs) 
                                    If TypeOf evtArgs.Node Is ConnectorBase Then 
                                                'Activate your custom tool here 
                                                diagram1.Controller.ActivateTool("LineLinkTool") 
                                    End If 
                        End Sub 
 
Sample: 
 
 
Video: 
 
 
Regards, 
 
Naganathan K G 



AL Allen March 2, 2018 09:58 PM UTC

Thank you Naganathan!
That is fine but since I wanted to use a custom connector class that inherits orglineconnector, how can I make use of my custom connector instead of the default connectors? the name of my custom connector is customConnector, which is in the PaletteGroupBar


NG Naganathan Ganesh Babu Syncfusion Team March 5, 2018 05:28 AM UTC

Hi Allen, 
 
We have created a sample with custom OrgLine connector to achieve your requirement. Please refer to the below sample. 
 
Sample: 
 
 
Regards, 
 
Naganathan K G 



AL Allen March 6, 2018 06:09 AM UTC

Thank you Neganathan,
How do you keep connecting if you have more than two nodes on the diagram sheet? I notice that the connector button remain pressed and I cannot connect more than once.  Either it should be un-pressed when I finish the first connection and then I press gain to proceed with the second connection or it has to stay active until I exit connecting (like with escape key or something like that).


NG Naganathan Ganesh Babu Syncfusion Team March 7, 2018 06:02 AM UTC

Hi Allen, 
 
We have modified the sample to achieve your requirement. we suggest you to use Diagram’s MouseUp and KeyPress event to stay active/deactive the activated tools always. Please refer to the below code example and modified sample. 
 
Code example: 
 
[VB] 
 
Private stayActive As Boolean = False 
AddHandler paletteGroupBar1.NodeSelected, AddressOf paletteGroupBar1_NodeSelected 
                                    AddHandler diagram1.MouseUp, AddressOf diagram1_MouseUp 
                                    AddHandler diagram1.KeyPress, AddressOf diagram1_KeyPress 
Private Sub diagram1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) 
            If e.KeyChar = CChar(ChrW(Keys.Escape)) Then 
                If TypeOf diagram1.Controller.ActiveTool Is CustomOrgLineConnectorTool Then 
                    diagram1.Controller.DeactivateTool(diagram1.Controller.ActiveTool) 
                End If 
                stayActive = False 
            End If 
                        End Sub 
Private Sub diagram1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) 
                                    If stayActive Then 
                                                'Activate your custom tool here 
                                                diagram1.Controller.ActivateTool("CustomLine") 
                                    End If 
                        End Sub 
 
Private Sub paletteGroupBar1_NodeSelected(ByVal sender As Object, ByVal evtArgs As NodeEventArgs) 
                                    If TypeOf evtArgs.Node Is ConnectorBase Then 
                                                'Activate your custom tool here 
                                                diagram1.Controller.ActivateTool("CustomLine") 
                                                stayActive = True 
                                    Else 
                                                If TypeOf diagram1.Controller.ActiveTool Is CustomOrgLineConnectorTool Then 
                                                            diagram1.Controller.DeactivateTool(diagram1.Controller.ActiveTool) 
                                                End If 
                                                stayActive = False 
                                    End If 
                        End Sub 
 
 
Sample: 
 
 
Regards, 
 
Naganathan K G 



NG Naganathan Ganesh Babu Syncfusion Team March 7, 2018 06:30 AM UTC

Hi Allen, 
 
Please ignore out previous update. 
 
We suggest you to use diagram1.Controller.ActiveTool “SingleActionTool” property to set as False to stay active the activated tool always. Also use Diagram’s KeyPress event to deactivate the currently activated tool by using diagram1.Controller’s DeactivateTool() method. Please refer to the below code example and sample. 
 
Code example: 
 
[VB] 
 
AddHandler paletteGroupBar1.NodeSelected, AddressOf paletteGroupBar1_NodeSelected 
AddHandler diagram1.KeyPress, AddressOf diagram1_KeyPress 
 
Private Sub diagram1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) 
If e.KeyChar = CChar(ChrW(Keys.Escape)) Then 
If TypeOf diagram1.Controller.ActiveTool Is CustomOrgLineConnectorTool Then 
diagram1.Controller.DeactivateTool(diagram1.Controller.ActiveTool) 
End If 
End If 
End Sub 
Private Sub paletteGroupBar1_NodeSelected(ByVal sender As Object, ByVal evtArgs As NodeEventArgs) 
If TypeOf evtArgs.Node Is ConnectorBase Then 
'Activate your custom tool here 
  diagram1.Controller.ActivateTool("CustomLine") 
Stay active the activated tool always 
diagram1.Controller.ActiveTool.SingleActionTool = False 
Else 
If TypeOf diagram1.Controller.ActiveTool Is CustomOrgLineConnectorTool Then 
diagram1.Controller.DeactivateTool(diagram1.Controller.ActiveTool) 
End If 
End If 
End Sub 
 
 
Sample 
 
 
Regards, 
 
Naganathan K G 

 [n1] 



AL Allen March 7, 2018 08:15 AM UTC

Dear Naganathan,

Thank you so much. I was shortly asking on a few issues, which I just resolved minutes ago

I still have one issue with it: when I deactivate the connection with Escape, the customLine button (under the PaletteGroupbar) still remains pressed. I have to press on another button within the same palette group. It doesn't unpress the button if I presse another button of different Palette group. So, it would be ideal to unpress the button of the customline when I press Escape 

Not really an issue but It would be nice to have a function that highlights a node when the mouse is hovering over it
Mouse pointer is arrow until it is over the node. Then it turns to cross.  To start drawing only when the mouse is over the Node, not outside of it.  


NG Naganathan Ganesh Babu Syncfusion Team March 8, 2018 05:20 AM UTC

Hi Allen, 
I still have one issue with it: when I deactivate the connection with Escape, the customLine button (under the PaletteGroupbar) still remains pressed. I have to press on another button within the same palette group.  
We suggest you to use get the currently selected item from the paletteGroupBar by using PaletteGroupBar’s SelectItem property and  use PaletteGroupView’s SelectNode() method to pass a parameter as null to unselect the nodes in current PaletteGroupbar. 
 
Please refer to the below code example: 
 
Code example: 
 
[VB] 
 
Private Sub diagram1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) 
            If e.KeyChar = CChar(ChrW(Keys.Escape)) Then 
                If TypeOf diagram1.Controller.ActiveTool Is CustomOrgLineConnectorTool Then 
                    diagram1.Controller.DeactivateTool(diagram1.Controller.ActiveTool) 
                End If 
                UnSelectNodeCurSymbolPalette(paletteGroupBar1, paletteGroupBar1.SelectedItem) 
            End If 
                        End Sub 
 
                        Private Sub UnSelectNodeCurSymbolPalette(ByVal groupBar As PaletteGroupBar, ByVal selectItem As Integer) 
                                    Dim groupView As PaletteGroupView = TryCast(groupBar.GroupBarItems(selectItem).Client, PaletteGroupView) 
                                    'Unselect the node in palette group bar while changing the current symbol palette 
                                    groupView.SelectNode(Nothing) 
                        End Sub 
It doesn't unpress the button if I presse another button of different Palette group. So, it would be ideal to unpress the button of the customline when I press Escape  
In order to achieve your requirement, we suggest you to use PaletterGroupbar’s “GroupBarItemSelectionChanging” event and follow the same procedure which is provided in above. 
 
Please refer to the below code example. 
 
Code example: 
 
[VB] 
 
AddHandler paletteGroupBar1.GroupBarItemSelectionChanging, AddressOf paletteGroupBar1_GroupBarItemSelectionChanging 
 
 
Private Sub paletteGroupBar1_GroupBarItemSelectionChanging(ByVal sender As Object, ByVal args As GroupBarItemSelectionChangingEventArgs) 
                        UnSelectNodeCurSymbolPalette(TryCast(sender, PaletteGroupBar), args.OldSelected) 
End Sub 
Not really an issue but It would be nice to have a function that highlights a node when the mouse is hovering over it 
Mouse pointer is arrow until it is over the node. Then it turns to cross.  To start drawing only when the mouse is over the Node, not outside of it.  
 
Also please use Diagram.Eventsink’s NodeMouseEnter/NodeMouseLeave events to add your logic codes as per your requirement.  
 
Code example: 
 
[VB] 
 
AddHandler diagram1.EventSink.NodeMouseEnter, AddressOf EventSink_NodeMouseEnter 
AddHandler diagram1.EventSink.NodeMouseLeave, AddressOf EventSink_NodeMouseLeave 
 
Private Sub EventSink_NodeMouseLeave(ByVal evtArgs As NodeMouseEventArgs) 
                                    Dim node As Node = evtArgs.Node 
                                    node.LineStyle.LineColor = tempColor 
                                    node.LineStyle.LineWidth = tempWidth 
                        End Sub 
                        Private Sub EventSink_NodeMouseEnter(ByVal evtArgs As NodeMouseEventArgs) 
                                    Dim node As Node = evtArgs.Node 
                                    tempColor = node.LineStyle.LineColor 
                                    node.LineStyle.LineColor = Color.Red 
                                    tempWidth = node.LineStyle.LineWidth 
                                    node.LineStyle.LineWidth = 2 
                        End Sub 

Sample: 
Regards, 
Naganathan K G 


Loader.
Up arrow icon