Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Link GotFocus and NewLink problem (Read 3170 times)
rzanni
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 11
Joined: Mar 18th, 2009
Link GotFocus and NewLink problem
Mar 18th, 2009 at 2:21pm
Print Post  
Hi,

I have two issues:

1. Is there any way to catch a Link GotFocus Event?
I want to do this in order to highlight the link when I pass othe mouse over it and only show the handles when I select the link.

2. I have 2 nodes connected by 1 link, what I want to do is reroute the link from the first node to the another incoming port in the second node but in this way:

Select the first node, start creating a new link from the existing outgoing port, delete the existing link (in order to create the sensation that the link was disconnected from the detination node) and start creating a the new link.

Whenever I start creating the new link (LinkCreating) I remove the existing one but I get the following error:

Null Reference exception:
Object reference not set to an instance of an object.

This is the code:

Private Sub doc_InitializeLink(ByVal sender As Object, ByVal e As MindFusion.Diagramming.LinkEventArgs) Handles doc.InitializeLink

Dim myExistingLink As DiagramLink

If e.Link.Origin.OutgoingLinks.Count > 0 Then
myExistingLink = e.Link.Origin.OutgoingLinks(0)
doc.Items.Remove(myExistingLink)
view.Refresh()
End If
End Sub

I hope someone can give me a hand with this.

Thanks.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link GotFocus and NewLink problem
Reply #1 - Mar 18th, 2009 at 3:25pm
Print Post  
Hi,

1. Handle MouseMove, convert the mouse position to diagram coordinates using ClientToDoc, and use GetLinkAt to find out if there's a link under the mouse.

2. What if you change the condition to If e.Link.Origin.OutgoingLinks.Count > 1 Then ... ? I'm not sure, but the currently drawn link might be already in that OutgoingLinks collection ,and that code would try to delete it. Even so, it might be safer to just set the existing link Visible = false, and delete it only after the LinkCreated event.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
rzanni
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 11
Joined: Mar 18th, 2009
Re: Link GotFocus and NewLink problem
Reply #2 - Mar 18th, 2009 at 4:11pm
Print Post  
Stoyan,

Thanks for your quick answer.

Problem 2 solved ( Visible=False and then delete)

I did what you mention for issue number 1 but the problem is that when I have many links next to each other, when I hover the mouse I get all of them highlighted. Maybe it has to be with the MaxDist parameter ( in order not to get the handles invisible I had to set this parameter to 5)

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link GotFocus and NewLink problem
Reply #3 - Mar 18th, 2009 at 4:35pm
Print Post  
Perhaps you should keep a reference to the last highlighted link, and unhighlight it on the next mouse move?
  
Back to top
 
IP Logged
 
rzanni
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 11
Joined: Mar 18th, 2009
Re: Link GotFocus and NewLink problem
Reply #4 - Mar 18th, 2009 at 5:55pm
Print Post  
That's exactly what I'm doing but since there are many links selected at the same time ( and I can't get a collection of them), I only can unselect one of them but the rest remain highlighted.

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link GotFocus and NewLink problem
Reply #5 - Mar 18th, 2009 at 6:31pm
Print Post  
I can't understand what are these links selected at the same time? Aren't you using GetLinkAt to get the link that should be highlighted? It returns just a single link...
  
Back to top
 
IP Logged
 
rzanni
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 11
Joined: Mar 18th, 2009
Re: Link GotFocus and NewLink problem
Reply #6 - Mar 18th, 2009 at 6:53pm
Print Post  
Stoyan,

This is the situation:

1. The highligt/unhighlight situation is being handle with the MouseMove Even (code below). I just did it with the GetItemAt instead of GetLinkAt because I want to highlight Nodes later (anyway I did it with GetLinkAt but the results are the same).

2. When I hover the mouse over 1 link it gets red and I save a reference of it.

3. Then I move the cursor off the link then it gets gray and it works great.

The problem is when you move the cursor off the link BUT there is another link next to it and then the MouseEvent is triggered again to highlight the new link but not to unhighlight the last one. In this situation you get 2 highlighted links and when you move the cursor again only the last one gets gray but the first one remains red.

Ufff.. that was a long, I hope I made myself clear.

CODE:

Dim myLastHoveredLink As DiagramLink

Private Sub view_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles view.MouseMove

Dim clientPoint As Point = Control.MousePosition
Dim documentPoint As Point = view.PointToClient(clientPoint)
Dim documentPoint2 As PointF = view.ClientToDoc(documentPoint)
Dim hoveredlink As DiagramLink
Dim hoveredNode As DiagramNode

Dim myType As Type
Dim hovereditem As DiagramItem = doc.GetItemAt(documentPoint2, False)


If Not hovereditem Is Nothing Then
myType = hovereditem.GetType()

If myType.Name = "DiagramLink" Then
hoveredlink = hovereditem
view.ModificationStart = ModificationStart.SelectedOnly
hoveredlink.Pen.Color = Color.Red
myLastHoveredLink = hoveredlink
view.Refresh()
End If
Else
If Not myLastHoveredLink Is Nothing Then
myLastHoveredLink.Pen.Color = Color.Gray
view.Refresh()
End If
view.ModificationStart = ModificationStart.AutoHandles
End If

End Sub
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link GotFocus and NewLink problem
Reply #7 - Mar 19th, 2009 at 3:51pm
Print Post  
You must reset the color of last hovered link not only when the currently hovered link is Nothing, but also when it is set to a different link. This worked for me:

Code
Select All
Private Sub view_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles view.MouseMove
	Dim clientPoint As Point = e.Location
	Dim documentPoint As PointF = view.ClientToDoc(clientPoint)
	Dim hoveredlink As DiagramLink

	Dim hovereditem As DiagramItem = diag.GetItemAt(documentPoint, False)
	If myLastHoveredLink IsNot Nothing And myLastHoveredLink IsNot hovereditem Then
		myLastHoveredLink.Pen = diag.LinkPen 'reset to default pen
	End If

	If hovereditem IsNot Nothing Then
		If TypeOf hovereditem Is DiagramLink Then
			hoveredlink = hovereditem
			view.ModificationStart = ModificationStart.SelectedOnly
			hoveredlink.Pen = New MindFusion.Drawing.Pen(Color.Red)
			myLastHoveredLink = hoveredlink
		End If
	Else
		view.ModificationStart = ModificationStart.AutoHandles
	End If
End Sub
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
rzanni
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 11
Joined: Mar 18th, 2009
Re: Link GotFocus and NewLink problem
Reply #8 - Mar 19th, 2009 at 5:00pm
Print Post  
Yes, now it works, but if you don't Refresh the DiagramView with Refresh() method after setting the Pen (in both cases),it doesn't work quite well.

Thank you very much.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint