Hi!
How to change Rack label position as my image example?
Now is this layout:
//Rack
[Serializable]
public class Rack : Display
{
//Rack colors
private static readonly Pen StandardPen = new Pen(Color.Black, 2);
private static readonly Pen HighlightPen = new Pen(Color.Green, 2);
//Cell Grid Size
private int CellGridSize = 3;
public Rack()
{
this.Label.Text = "Rack";
}
protected override GoGrid CreateGrid()
{
GoGrid grid = new RackGrid();
grid.Selectable = false;
grid.AutoRescales = true;
grid.Resizable = true;
grid.ResizesRealtime = true;
grid.Bounds = new RectangleF(0, 0, 100, 100);
grid.SnapDrag = GoViewSnapStyle.Jump;
grid.SnapResize = GoViewSnapStyle.Jump;
grid.CellSize = new SizeF(CellGridSize, CellGridSize);
grid.Style = GoViewGridStyle.None;
grid.Pen = new Pen(Color.Black, 2);
grid.Brush = null;
return grid;
}
// make sure the Rack's Label is positioned above the top-left corner of the Grid;
// this makes it potentially useful for selection and dragging even if all of the
// grid is covered by Items
public override void LayoutChildren(GoObject childchanged)
{
if (this.Count >= 2)
{
GoGrid grid = this.Grid;
GoText label = this.Label;
if (grid != null && label != null)
{
label.SetSpotLocation(BottomLeft, new PointF(grid.Left, grid.Top - 1));
}
}
}
// the Location of a Rack is actually the Position of its Grid
public override PointF Location
{
get { return this.Grid.Position; }
set
{
SizeF off = GoTool.SubtractPoints(this.Grid.Position, this.Position);
SizeF pos = GoTool.SubtractPoints(value, off);
this.Position = new PointF(pos.Width, pos.Height);
}
}
public override void SetHighlight(bool show)
{
GoGrid grid = this.Grid;
if (grid != null)
{
if (show)
{
grid.Pen = Rack.HighlightPen;
}
else
{
grid.Pen = Rack.StandardPen;
}
}
}
}
[Serializable]
public class RackGrid : GoGrid
{
//Cell Grid Size
private int CellGridSize = 3;
public RackGrid()
{
}
// the grid in a Rack only snaps Items
public override bool CanSnapPoint(PointF p, GoObject obj, GoView view)
{
if (!(obj is GraphNode))
{
return false;
}
// do standard checks, such as whether the grid is a child of the OBJ,
// the value of the grid's snap style, whether the OBJ intersects with the grid,
// and whether the mouse point is in the grid
return base.CanSnapPoint(p, obj, view);
}
// it can be resized only in positive multiples of Item.UnitSize
public override RectangleF ComputeResize(RectangleF origRect, PointF newPoint, int handle, SizeF min, SizeF max, bool reshape)
{
RectangleF r = base.ComputeResize(origRect, newPoint, handle, min, max, reshape);
r.Width = Math.Max(1, (float)Math.Round(r.Width / CellGridSize)) * CellGridSize;
r.Height = Math.Max(1, (float)Math.Round(r.Height / CellGridSize)) * CellGridSize;
return r;
}
}