GoDrawView: sheet boundaries

Hallo i have one more question. Is it possible that the user can not move nodes outside the sheet boundaries. How can i achieve that?

Kind regards

There's multiple ways to do this (for example LimitedNode in Demo1).
But, this is probably the easiest: derive a GoSheet that limits drag.
[code]
using System;
using System.Drawing;
using System.Text;
using Northwoods.Go;
namespace Planogrammer {
class ConstraintedSheet : GoSheet, IGoDragSnapper {
public ConstraintedSheet() {
}
public bool CanSnapPoint(PointF p, GoObject obj, GoView view) {
return true;
}
public bool SnapOpaque {
get { return true; } // don't care about any grids that might be underneath
}
public PointF SnapPoint(PointF p, GoObject obj, GoView view) {
// normalize the object's Bounds as if the Location were always the Position
PointF loc = obj.Location;
RectangleF b = obj.Bounds;
b.X += (p.X - loc.X);
b.Y += (p.Y - loc.Y);
// position the object so that it fits inside the margins
RectangleF r = this.MarginBounds;

// or within the paper
// RectangleF r = this.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;
}
}
}
[/code]
and, you have to either override CreateSheet in your GoView class, or (if you don't have one), you can just set
goView1.Sheet = CreateSheet()
and add this code to your main form:
[code]
public GoSheet CreateSheet() {
GoSheet sheet = new ConstraintedSheet();
sheet.Visible = (this.goView1.SheetStyle != GoViewSheetStyle.None);
sheet.Printable = false;
sheet.Selectable = false;
PrintDocument pd = new PrintDocument();
PageSettings ps = pd.DefaultPageSettings;
sheet.UpdateBounds(ps, this.goView1.PrintScale);
GoRectangle paper = sheet.Paper;
Color color = this.goView1.Document.PaperColor;
if (color == Color.Empty)
color = Color.White;
paper.BrushColor = color;
return sheet;
}
[/code]