Nevron Forum

Getting NDrawingDocument bounds

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

By Joseph King - Thursday, March 18, 2010


I have an instance of NDrawingDocument in which I have placed a number of objects and then used a layout manager to arrange them. The last thing I would like to do, before displaying the drawing to the user, is place a legend in the bottom right corner of my drawing. Unfortunately I am unable to find the bottom right corner. When I get the Bounds property for the NDrawingDocument instance it is not even close to the bottom right corner. It is in the bottom right quandrant but nowhere near the bottom right corner.

Any ideas on what I am doing wrong?

j.
By Nevron Support - Wednesday, March 24, 2010

Hi,

The document bounds are not the bounds of the viewport, that is the rectangle from the document space shown by the view. Placing a sticky shape at the bottom of the viewport can be achieved by subscribing for the view transformation changed event and repositioning the shape. For example:

NShape shape;
NDrawingView drawingView;

private void Form1_Load(object sender, EventArgs e)
{
drawingView = new NDrawingView();
drawingView.Dock = DockStyle.Fill;
Controls.Add(drawingView);

NDrawingDocument drawingDocument = new NDrawingDocument();
drawingView.Document = drawingDocument;

shape = new NRectangleShape(0, 0, 100, 100);
drawingDocument.ActiveLayer.AddChild(shape);

drawingView.TransformationsChanged += new EventHandler(view_TransformationsChanged);
}

void view_TransformationsChanged(object sender, EventArgs e)
{
NRectangleF bounds = shape.Bounds;
bounds.X = drawingView.Viewport.Right - shape.Bounds.Width;
bounds.Y = drawingView.Viewport.Bottom - shape.Bounds.Height;
shape.Bounds = bounds;
}