Hi Michal,
The behavior that you want to achieve is very similar to the Fit view layout of the drawing view. The only difference being that you are fitting the view to some nodes bounds. The following code will achieve this behavior in all possible cases of measurement units and drawing scales.
// get the bounds of the selected objects
NRectangleF bounds = NFunctions.ComputeNodesBounds(view.Selection.Nodes, null);
// get the scaling of scene units to world (painting units)
// for documents without a drawing scale these are equal to 1
float sceneToWorldScaleX = document.SceneScaleToWorldX;
float sceneToWorldScaleY = document.SceneScaleToWorldY;
// compute the page scale
// for documents measured in pixels this is equal to 1
float pageScale = view.MeasurementUnitConverter.ConvertX(document.WorldMeasurementUnit, NGraphicsUnit.Pixel, 1);
// determine the zoom
NSizeF windowSize = view.WindowSize;
float zoom = Math.Min(windowSize.Width / (bounds.Width * pageScale * sceneToWorldScaleX),
windowSize.Height / (bounds.Height * pageScale * sceneToWorldScaleY));
// zoom to nodes bounds center
view.Zoom(zoom, bounds.Center);
Hope this helps - questions or comments - please feel free...
Best regards,
Ivo Milanov