Hi,
1) If you want to show the selected node in the center of the current viewport, use the following code:
diagram.NodeSelected += (s, e) =>
{
var node = e.Node;
var dpi = 96; // 96 dpi used just for testing, you'll want the actual device dpi when using this conversion
var graphics = diagram.CreateMeasureGraphics();
var viewportHeight = MeasureUnit.Inch.Convert(diagramView.Height / dpi, diagram.MeasureUnit, graphics);
var viewportWidth = MeasureUnit.Inch.Convert(diagramView.Width / dpi, diagram.MeasureUnit, graphics);
diagram.ScrollX = node.Bounds.X - viewportWidth / 2 + node.Bounds.Width / 2;
diagram.ScrollY = node.Bounds.Y - viewportHeight / 2 + node.Bounds.Height / 2;
};
Please note, that the view will scroll only within the actual diagram bounds, so if the selected node is close to the top or left edge of the document, it won't show in the center. To make sure that doesn't happen, you may want to increase the diagram bounds to ensure enough space between the nodes and the edges.
2) If you wish to actually move the node to the center of the document, and not just set the viewport on it, set its Bounds or use the Move method:
node.Move(diagram.Bounds.Width / 2 - node.Bounds.Width / 2,
diagram.Bounds.Height / 2 - node.Bounds.Height / 2);
Regards,
Lyubo
MindFusion