void gViewer_ObjectUnderMouseCursorChanged(object sender, ObjectUnderMouseCursorChangedEventArgs e) { selectedObject = e.OldObject != null ? e.OldObject.DrawingObject : null; if (selectedObject != null) { RestoreSelectedObjAttr(); gViewer.Invalidate(e.OldObject); selectedObject = null; } if (gViewer.SelectedObject == null) { infoLabel.Text = "No object under the mouse"; gViewer.SetToolTip(toolTip, ""); } else { selectedObject = gViewer.SelectedObject; var edge = selectedObject as Edge; if (edge != null) { selectedObjectAttr = edge.Attr.Clone(); edge.Attr.Color = Color.Blue; gViewer.Invalidate(e.NewObject); // here we can use e.Attr.Id or e.UserData to get back to the user data gViewer.SetToolTip(toolTip, String.Format("edge from {0} to {1}", edge.Source, edge.Target)); } else if (selectedObject is Microsoft.Msagl.Drawing.Node) { selectedObjectAttr = (gViewer.SelectedObject as Microsoft.Msagl.Drawing.Node).Attr.Clone(); (selectedObject as Microsoft.Msagl.Drawing.Node).Attr.Color = Color.Green; // // here you can use e.Attr.Id to get back to your data gViewer.SetToolTip(toolTip, String.Format("node {0}", (selectedObject as Microsoft.Msagl.Drawing.Node).Attr.Id)); gViewer.Invalidate(e.NewObject); } infoLabel.Text = selectedObject.ToString(); } }
private void Gviewer_ObjectUnderMouseCursorChanged(object sender, ObjectUnderMouseCursorChangedEventArgs e) { RestorePreviouslyHoverObjectColor(e.OldObject); if (e.OldObject != null) { gviewer.Invalidate(e.OldObject); } if (gviewer.ObjectUnderMouseCursor == null) { gviewer.SetToolTip(viewerToolTip, ""); return; } selectedObjectMouseHover = gviewer.ObjectUnderMouseCursor; DrawingObject currentDrawingObject = selectedObjectMouseHover.DrawingObject; string selectedObjetLabel = null; if (currentDrawingObject is Edge) { var edge = currentDrawingObject as Edge; edge.Attr.Color = Color.Blue; selectedObjetLabel = edge.Attr.Id; // Attr.Id holds the relationship information } else if (currentDrawingObject is Node) { var node = currentDrawingObject as Node; node.Attr.Color = Color.Green; string entityName = node.Attr.Id; selectedObjetLabel = entityRelations.GetEREntitieAttributesByEntityName(entityName)?.FirstOrDefault <EREntityAttribute>()?.Description; } else { return; } gviewer.SetToolTip(viewerToolTip, selectedObjetLabel); if (e.NewObject != null) { gviewer.Invalidate(e.NewObject); } }