Nevron Forum

Scrool to a Specific Shape

https://www.nevron.com/Forum/Topic5095.aspx

By Ashton Hobbs - Monday, April 18, 2011

Is it possible to scroll to a specific shape in the diagram given the shapes UniqueID (or some other identifier for the shape).

I have an external list of the shapes in the diagram and when a user clicks on a an item in my list I want to scroll the diagram to ensure that the specific shape is visible (and selected).

Thanks
By Nevron Support - Tuesday, April 19, 2011

Hi,

Here’s a sample code how to select a shape by its name (you can use also its ID or UniqueID) and center the viewport on it:

 

// Get the shape and select it

NShape shape = (NShape)document.ActiveLayer.GetChildByName("MyShape");

view.Selection.SingleSelect(shape);

 

// Center the viewport at the shape's center

NPointF origin = view.ViewportOrigin;

NPointF offset = shape.Center - view.Viewport.Center;

view.ViewportOrigin = new NPointF(origin.X + offset.X, origin.Y + offset.Y);