Author
|
Message
|
Bruce Guthrie
|
|
Group: Forum Members
Last Active: 6 Years Ago
Posts: 14,
Visits: 2
|
Hello, I like the world maps and the one thing i would like to find out is, is it possible to add a mouse click event so that when the user clicks on a country the name or any other information can be captured for futher use. there is already the interactivity tool and i tried to add the mouse event click event but was unable to come up with the correct code. could you post the code in vb.net. Regards Bruce.
|
|
|
Pavel Vladov
|
|
Group: Forum Members
Last Active: 7 Years Ago
Posts: 33,
Visits: 2
|
Hello Bruce, If you have followed the principles shown in the map examples, then the shapes in the diagram created by the map importer are named after the countries. So all you have to do is to get the name of the shape (use shape.Name) the user has clicked on. Questions or comments, please let me know.
Best Regards, Pavel
|
|
|
Bruce Guthrie
|
|
Group: Forum Members
Last Active: 6 Years Ago
Posts: 14,
Visits: 2
|
Pavel yes i have already seen the shape.Name and that is not a problem. But what i cannot do or find out how to do is assign the mouse click event to the shape. below is one of my crude attempts to get the country name into a text box but it does not work. Can you help me with how to assing the mouse click or event sink or what ever i need to the country shape so i can detect the click event. AddHandler Form1.worldmap1.EventSinkService.NodeClick, AddressOf CountryClick Private Sub CountryClick(ByVal args As NNodeViewEventArgs)Form1.TextBox1.Text = shape.Name End Sub
|
|
|
Pavel Vladov
|
|
Group: Forum Members
Last Active: 7 Years Ago
Posts: 33,
Visits: 2
|
Hi Bruce, cast the args.Node to NShape object, because this is the node that was clicked.
|
|
|
Bruce Guthrie
|
|
Group: Forum Members
Last Active: 6 Years Ago
Posts: 14,
Visits: 2
|
hello i am getting no where fast on this one, i cannot see how to attach the nodeclick event to the country shape. where do i add the code for the event handler? is in in the form load event where i have the following code AddHandler worldmap1.EventSinkService.NodeMouseUp, AddressOf EventSinkService_NodeMouseUpAddHandler worldmap1.EventSinkService.NodeClick, AddressOf CountryClicki can get the nodemouseup but it retruns a CustomPath, the nodeclick does not fire atall. i also tried putting the event handler in the Private Class NFeatureCallback routine where the shape is created but this did not work either. AddHandler Form1.worldmap1.EventSinkService.NodeClick, AddressOf CountryClickplease help here with where i need to assign the event handler and to what i need to try and attach it to. regards bruce.
|
|
|
Pavel Vladov
|
|
Group: Forum Members
Last Active: 7 Years Ago
Posts: 33,
Visits: 2
|
Hi Bruce, I recommend you subscribe to the NodeMouseDown event of the document's Event Sink Service (for example in the Form Load event): document.EventSinkService.NodeMouseDown += new NodeMouseEventHandler(EventSinkService_NodeMouseDown);Then in the event handler you will need the following code to get the clicked shape: private void EventSinkService_NodeMouseDown(NNodeMouseEventArgs args) { if (args.Node is NShape) { // Get the clicked shape NShape shape = (NShape)args.Node; MessageBox.Show(shape.Text); } } I hope this helps. Let me know if you have any questions or if you need assistance. Best Regards, Pavel
|
|
|
Bruce Guthrie
|
|
Group: Forum Members
Last Active: 6 Years Ago
Posts: 14,
Visits: 2
|
hello i try what you suggest but i still do not get the shape. AddHandler worldmap1.EventSinkService.NodeMouseDown, AddressOf EventSinkService_NodeMouseDownis in form load. then i have following code but the args.node is a custom path and not a shape so i cannot get the name. Private Sub EventSinkService_NodeMouseDown(ByVal args As NNodeMouseEventArgs)Dim shape As NShape = TryCast(args.Node, NShape)MessageBox.Show(shape.Text) End SubCan you help again please i just cannot see where to get the shape from. Regards Bruce
|
|
|
Pavel Vladov
|
|
Group: Forum Members
Last Active: 7 Years Ago
Posts: 33,
Visits: 2
|
Hi, Bruce, What I've posted in my previous reply is the right way to get the clicked shape. If you send me your sample project I'll be able to assist you better and tell you exactly where the problem is.
Best Regards, Pavel Vladov
|
|
|
Bruce Guthrie
|
|
Group: Forum Members
Last Active: 6 Years Ago
Posts: 14,
Visits: 2
|
Hello i attach my project for you to look at. i hope it is something simple, i am sure it is. Regards Bruce
|
|
|
Pavel Vladov
|
|
Group: Forum Members
Last Active: 7 Years Ago
Posts: 33,
Visits: 2
|
Hi Bruce, in the mouse up event use the following code: Private Sub EventSinkService_NodeMouseUp(ByVal args As NNodeMouseEventArgs) If args.Button = MouseButtons.Left Then Dim viewCoordinates As PointF = New PointF(args.X, args.Y) Dim sceneCoordinates As PointF = worldmap1.SceneToWorld.InvertPoint(viewCoordinates) Dim node As INNode = args.Node
While (node IsNot Nothing) And (TypeOf node Is NShape = False) node = node.ParentNode End While
If node Is Nothing Then Exit Sub
Dim shape As NShape = TryCast(node, NShape)
'Dim shape As NShape = TryCast(args.Node, INDiagramElement)
MessageBox.Show(String.Format("Shape Name: '{0}', Type: '{1}'", shape.Name, CType(shape.ParentNode, NLayer).Name))
' mark as handled and processed to stop bubbling and processing args.Handled = True End If End Sub Note how we take the type of the shape - we just look for the layer the shape is placed in. The layer of the shape is its parent node. I hope this helps. Best Regards, Pavel Vladov
|
|
|