Showing document of fixed size


I am not sure how I should handle this task:
1. GoDocument derived objects should be of fixed size (think of A4 sheet of paper for drawing something)
2. GoView should display whole document (no scrollbars). If GoView is smaller than the document, it should scale it down, if larger, it should center the document display and leave some borders
3. User should not be able to move diagram elements outside the fixed boundaries of GoDocument
can you please point me to a sample code, which is doing similar task, or suggest ways of do the task.
At the moment I set Size for GoDocument and declare it FixedSize - not sure what this do, and also call GoView::RescaleToFit() when a document is loaded or view resized
goView1.SheetStyle = GoViewSheetStyle.WholeSheet;
goView1.BackgroundHasSheet = true;
goView1.ShowHorizontalScrollBar = GoViewScrollBarVisibility.Hide;
goView1.ShowVerticalScrollBar = GoViewScrollBarVisibility.Hide;
gets you requirements 1 & 2.
but the mouse wheel still scrolls and zooms, and you can move objects out of the sheet.
back with more later...

Thanks, Jake!

I did not know about SheetStyle property.
I tried to solve the problem myself, and this is what I've done:
1. I set size of document and declare it FixedSize=true;
2. I call this method (SetupViewBounds) whenever window hosting goView1 (Host) is resized
protected void SetupViewBounds()
{ GoDocument doc = goView1.Document; int HostWidth = this.ClientRectangle.Width - 2 * BorderWidth; int HostHeight = this.ClientRectangle.Height - 2 * BorderWidth; // goview should have the same aspect ratio as the document float DocAspectRatio = (float)doc.Size.Width / (float)doc.Size.Height; float HostAspectRatio = (float)HostWidth / (float)HostHeight; if (DocAspectRatio > HostAspectRatio) { // this means that document shape is longer that that of host goView1.Width = HostWidth; goView1.Height = (int)((float)(HostWidth) / DocAspectRatio); } else { // this means that document shape is taller that that of host goView1.Height = HostHeight; goView1.Width = (int)((float)(HostHeight) * DocAspectRatio); } float newscale = (float)goView1.Width / (float)doc.Size.Width; goView1.DocScale = newscale;

// center the GoView inside the Host client rectangle
goView1.Left = BorderWidth + (Width - goView1.Width) / 2;
goView1.Top = BorderWidth + (Height - goView1.Height) / 2;

I'll read about and try your suggestions.
Thanks again

to disable mouse wheel scrolling and zooming…

create an override of the GoToolManager:
public class ToolManagerNoZoom : GoToolManager {
public ToolManagerNoZoom(GoView v) : base(v) { }
public override void DoMouseWheel() {
// no-op
and install by overriding GoView.CreateDefaultTool (if you have a GoView subclass) or by:
goView1.DefaultTool = new ToolManagerNoZoom(this.goView1);
goView1.Tool = goView1.DefaultTool ;
  1. User should not be able to move diagram elements outside the fixed boundaries of GoDocument
replace the Sheet's grid with this class
public class LimitedGrid : GoGrid {
public LimitedGrid() { }
public override bool CanSnapPoint(PointF p, GoObject obj, GoView view) {
return true;
public override PointF SnapPoint(PointF p, GoObject obj, GoView view) {
// modified from class SwimLane. See that code if you want to avoid the margins.
if (obj == null) return p;
// normalize the object's Bounds as if the Location were always the Position
PointF loc = obj.Location;
RectangleF b = (view.Selection.Contains(obj) ? GoDocument.ComputeBounds(view.Selection, view) : obj.Bounds);
b.X += (p.X - loc.X);
b.Y += (p.Y - loc.Y);
// position the object so that it fits inside the sheet
RectangleF r = view.Sheet.Bounds ;
if (b.Right > r.Right)
p.X -= (b.Right - r.Right);
if (b.Left < r.Left)
p.X += (r.Left - b.Left);
if (b.Bottom > r.Bottom)
p.Y -= (b.Bottom - r.Bottom);
if (b.Top < r.Top)
p.Y += r.Top - b.Top;
return p;
by doing this:
goView1.Grid = new LimitedGrid();


thank you very much, very helpful!