Change position of label in Rack

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;
    }
}

First, you’ll need a copy of RotatedText, which is available here, but isn’t in the kit.



http://www.nwoods.com/forum/uploads/RotatedText.cs



Then, you’ll need to change LayoutChildren to position the label appropriately.

Hi Jake! Thank you for information.

I inserted RotatedText.cs
in my solution…

Based on Planogrammer4 example ( WinForms ), how LayoutChildren will stay? Please, can you send me an example of LayoutChildren ( Planogrammer4 example )

Thank you very much!!

using System;
using System.Drawing;
using Northwoods.Go;

namespace Planogrammer {
// a Rack represents a framework where Items may be hung for display
[Serializable]
public class Rack : Display {
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(Item.UnitSize, Item.UnitSize);
  grid.Style = GoViewGridStyle.Line;
  grid.Pen = Rack.StandardPen;
  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;
    }
  }
}

public static readonly Pen StandardPen = new Pen(Color.Black, 2);
public static readonly Pen HighlightPen = new Pen(Color.Fuchsia, 2);

}

try adding this:



protected override GoText CreateLabel() {

RotatableText label = new RotatableText();

label.Selectable = false;

label.Multiline = true;

label.Editable = true;

label.FontSize = 11;

label.TransparentBackground = false;

label.BackgroundColor = Color.White;

label.Bordered = true;

// settings for rotation.

label.AutoResizes = false;

label.Alignment = Middle;

label.Angle = 270;

return label;

}



public override void LayoutChildren(GoObject childchanged) {

if (this.Count >= 2) {

GoGrid grid = this.Grid;

GoText label = this.Label;

if (grid != null && label != null) {

label.Width = grid.Height;

PointF center = grid.GetSpotLocation(MiddleLeft) - new SizeF(label.Height/2+1, 0);

label.Center = center;

}

}

}



Hi Jake!!

Thank you very much!!!!!
Perfect example!! Thanks!!