My client would like to know if we was create a node that contains some number of boxes on it. A block represents a device operation. That device has storage locations and we would like to show those locations.
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
using Northwoods.Go;
[Serializable]
public class StorageNode : GoBasicNode {
public StorageNode()
{
this.Add(new GoListGroup()); // LeftBoxes
this.Add(new GoListGroup()); // RightBoxes
}
this.Text = "Try this";
this.MiddleLabelMargin = new SizeF(200, 100); // makes the node a reasonably big, fixed size.
LeftBoxes.Selectable = false;
LeftBoxes.Spacing = 5.0F; // adds space between boxes
RightBoxes.Selectable = false;
RightBoxes.Spacing = 5.0F;
}
{
// create the bigger circle/ellipse around and behind the port
LinearGradientRoundedRectangle rr4 = new LinearGradientRoundedRectangle(); // from Demo1
rr4.Bounds = new RectangleF(825, 190, 100, 50);
rr4.EndColor = Color.LightBlue;
rr4.Pen = Pens.LightBlue;
rr4.Selectable = false;
return rr4;
}
{
// a box is a GoRectangle and a GoText parented by a GoGroup
// the group is then added to the left or right GoListGroup
GoText t = new GoText();
t.Text = label;
t.Selectable = false;
r.Selectable = false;
r.Size = new SizeF(60, 20);
g.Selectable = false;
g.Add(t);
t.SetSpotLocation(MiddleCenter, r, MiddleCenter);
{
this.LeftBoxes.Add(g);
}
else
{
this.RightBoxes.Add(g);
}
return g;
}
{
if (this.Count < 5) return; // avoid layout until all parts added
base.LayoutChildren(childchanged);
if (this.Shape != null)
{
float vpad = 10;
float hpad = 20;
LeftBoxes.SetSpotLocation(TopLeft, this.Shape, TopLeft, hpad, vpad);
RightBoxes.SetSpotLocation(TopRight, this.Shape, TopRight, -hpad, vpad);
}
}
{
get { return this[2] as GoListGroup; }
}
public GoListGroup RightBoxes
{
get { return this[3] as GoListGroup; }
}
}
}
sn.Initialize();
sn.Location = new PointF(200, 250);
sn.AddBox("A", true);
sn.AddBox("B", true);
doc.Add(sn);
sn.Initialize();
sn.Location = new PointF(400, 250);
sn.AddBox("A", true);
sn.AddBox("B", true);
sn.AddBox("C", true);
sn.AddBox("D", true);
sn.AddBox("X", false);
sn.AddBox("Y", false);
doc.Add(sn);
Can you show us a mockup (e.g. from Paint or powerpoint) that shows what you want?
Does this give you the idea. Don’t mind my poor PaintBrush skills. :)
public class StorageNodeB : GoBasicNode {
public StorageNodeB() {
this.Add(new GoListGroup()); // LeftBoxes
this.Add(new GoListGroup()); // RightBoxes
this.Add(new GoImage()); // icon
}
LabelSpot = GoObject.Middle;
this.MiddleLabelMargin = new SizeF(20, 20);
LeftBoxes.Selectable = false;
LeftBoxes.Spacing = 5.0F; // adds space between boxes
RightBoxes.Selectable = false;
RightBoxes.Spacing = 5.0F;
}
GoText label = base.CreateLabel(name);
label.Multiline = true;
return label;
}
protected override GoShape CreateShape(GoPort p) {
// create the bigger circle/ellipse around and behind the port
LinearGradientRoundedRectangle rr4 = new LinearGradientRoundedRectangle(); // from Demo1
rr4.Bounds = new RectangleF(825, 190, 100, 50);
rr4.EndColor = Color.LightBlue;
rr4.Pen = Pens.LightBlue;
rr4.Selectable = false;
return rr4;
}
// a box is a GoRectangle and a GoText parented by a GoGroup
// the group is then added to the left or right GoListGroup
GoText t = new GoText();
t.Text = label;
t.Selectable = false;
r.Selectable = false;
r.Size = new SizeF(40, 40);
g.Selectable = false;
g.Add(t);
t.SetSpotLocation(MiddleLeft, r, MiddleRight, 15, 0);
this.LeftBoxes.Add(g);
} else {
this.RightBoxes.Add(g);
}
return g;
}
if (this.Count < 6) return; // avoid layout until all parts added
GoShape back = this.Shape;
GoText label = this.Label;
if (back != null && label != null) {
SizeF margin = this.MiddleLabelMargin;
PointF center = back.Center;
float newWidth = Math.Max(hpad + Image.Width + label.Width, hpad + LeftBoxes.Width + RightBoxes.Width);
float newHeight = margin.Height + Math.Max(label.Height, Image.Height) + margin.Height + LeftBoxes.Height + margin.Height;
label.SetSpotLocation(TopLeft, this.Image, TopRight, margin.Width, 0);
RightBoxes.SetSpotLocation(TopLeft, this.LeftBoxes, TopRight, margin.Width, 0);
this.Port.Bounds = back.Bounds;
}
}
get { return this[2] as GoListGroup; }
}
public GoListGroup RightBoxes {
get { return this[3] as GoListGroup; }
}
public GoImage Image {
get { return this[4] as GoImage; }
}
Some further comments on last night’s post…
Thanks for the example.
- MiddleLabelMargin
- CreatShape
- CreateLabel
FYI…
GoText has TopLeftMargin and BottomRightMargin, you could substitute those. (or just hardcode some margins)
I’m a bit confused by this line.
this.Port.Bounds = back.Bounds;
GoBasicNode either has a little port in the middle of the node, or the background object is the Port. This line of code (used when the label is over the middle of the node) sets the bounds of the background object to be the active “port” for the Node. GoTextNode has a different port set up, so it has no equivalent.
Can you explain this Code:
this.Add(new GoListGroup());
this.Add(new GoImage());
{
get { return this[2] as GoListGroup; }
}
public GoListGroup NestTextBoxes
{
get { return this[3] as GoListGroup; }
}
public GoImage Image
{
get { return this[4] as GoImage; }
}
Forget that last question. I created properties and private fields and made direct references to the boxes and Image instead of the index.
The private members complicate serialization and object Copy.