I am taking advantage of the Layout features in GoDiagram.
That might not be want you want, since the topic that Jake refers to also rescales the view.
If you want to change the size of your document to just fit around your newly laid out objects, you could do this instead:
RectangleF r = goView1.ComputeDocumentBounds(); // figure out how big the occupied area of the document really is
goView1.Document.Bounds = r; // resize document to just hold the objects
goView1.DocExtentCenter = new PointF(r.X+r.Width/2, r.Y+r.Height/2); // recenter the view at the document's center
If you just want to scroll the view without changing the document’s size, try something like:
RectangleF r = goView1.ComputeDocumentBounds(); // figure out how big the occupied area of the document really is
goView1.SheetStyle == GoViewSheetStyle.Sheet; // allow scrolling beyond end of document bounds
goView1.DocExtentCenter = new PointF(r.X+r.Width/2, r.Y+r.Height/2); // recenter the view at the document's center
All I want to do is place the diagram at the top middle of the View when I call Layout.
Try this code.
-
set your view up:
this.SheetStyle = GoViewSheetStyle.Sheet; -
Call CenterDoc() after every Layout.
-
Add this code to your view:
public virtual void CenterDoc()
{
RectangleF docb = this.Document.Bounds;
Size viewsz = this.ClientSize;
this.DocPosition = new PointF(docb.X + docb.Width / 2 - viewsz.Width / 2,
this.DocPosition.Y);
}
public override SizeF DocumentSize {
get {
SizeF s = base.DocumentSize;
s.Height = Math.Max(this.Doc.Size.Height, this.ClientSize.Height);
return s;
}
}
public override PointF DocumentTopLeft {
get {
PointF tl= base.DocumentTopLeft;
tl.Y = 0;
return tl;
}
}