/// <summary> /// Determines the bounding box of all the objects and update /// the scroll min position. If there are any nodes falling outside /// translate everything until they are visible /// </summary> public void UpdateBoundingBox() { var bbox = NodeExtensions.GetBoundingBox(Nodes.Select(n => n.Area)); int left = bbox.Left; int top = bbox.Top; int right = bbox.Right; int bottom = bbox.Bottom; // if nodes are outside the boundaries move all the nodes so they become visible if (left < 0) { right += Math.Abs(left); foreach (var n in Nodes) { n.Position = new Point(n.Position.X + Math.Abs(left), n.Position.Y); } } if (top < 0) { bottom += Math.Abs(top); foreach (var n in Nodes) { n.Position = new Point(n.Position.X, n.Position.Y + Math.Abs(top)); } } AutoScrollMinSize = new System.Drawing.Size((int)((right + 1) * Zoom), (int)((bottom + 1) * Zoom)); }
/// <summary> /// Draw the entire diagram to a bitmap and return it /// </summary> /// <returns>A bitmap of the entire diagram</returns> public Image AsImage() { // determine the bounding box var bbox = NodeExtensions.GetBoundingBox(Nodes.Select(n => n.Area)); bbox = new Rectangle(0, 0, bbox.Right + 1, bbox.Bottom + 1); bbox.Inflate(NodeSize.Width, NodeSize.Height); Bitmap bmp = new Bitmap(bbox.Width, bbox.Height); using (Graphics g = Graphics.FromImage(bmp)) { DrawContents(g, bbox, new Point(0, 0), 1); } return(bmp); }