I have a class, that insert objects, just with label, as FlowCharter example, and I would like to have a class with the same resources, objects, but these objects with a top image. How can I do it?
See my basic class:
//A node representing a step in a flowchart
[Serializable]
public class GraphNode : GoTextNode
{
//Variables
private const int ChangedKind = GoObject.LastChangedHint + 7;
private GraphNodeKind myKind = GraphNodeKind.Step;
//Constructor
public GraphNode()
{
InitCommon();
}
//Constructor with parameter
public GraphNode(GraphNodeKind k)
{
InitCommon();
this.Kind = k;
}
private void InitCommon()
{
//Assume GraphNodeKind.Step
this.Label.Wrapping = true;
this.Label.Editable = true;
this.Label.Alignment = Middle;
this.Text = "Step";
this.Editable = true;
this.TopLeftMargin = new SizeF(10, 5);
this.BottomRightMargin = new SizeF(10, 5);
this.Shadowed = true;
this.Background = new GoDrawing(GoFigure.Rectangle);
Color first = Color.FromArgb(159, 232, 0);
Color second = Color.White;
this.Shape.FillShapeHighlight(first, second);
}
//Adjust port positions for certain background shapes
public override void LayoutChildren(GoObject childchanged)
{
base.LayoutChildren(childchanged);
GoDrawing draw = this.Background as GoDrawing;
if (draw != null)
{
PointF tempPoint;
if (draw.Figure == GoFigure.ManualOperation || draw.Figure == GoFigure.Input || draw.Figure == GoFigure.Output)
{
if (this.RightPort != null)
{
draw.GetNearestIntersectionPoint(new PointF(this.RightPort.Center.X + .01f, this.RightPort.Center.Y), this.RightPort.Center, out tempPoint);
this.RightPort.Right = tempPoint.X;
}
if (this.LeftPort != null)
{
draw.GetNearestIntersectionPoint(new PointF(this.LeftPort.Center.X + .01f, this.LeftPort.Center.Y), this.LeftPort.Center, out tempPoint);
this.LeftPort.Left = tempPoint.X;
}
}
}
}
//When the mouse passes over a node, display all of its ports.
//All ports on all nodes are hidden when the mouse hovers over the background.
public override bool OnMouseOver(GoInputEventArgs evt, GoView view)
{
ProcessView v = view as ProcessView;
if (v != null)
{
foreach (GoPort p in this.Ports)
{
p.Style = GoPortStyle.Ellipse;
}
}
return false;
}
public GraphNodeKind Kind
{
get { return myKind; }
set
{
GraphNodeKind old = myKind;
if (old != value)
{
myKind = value;
Changed(ChangedKind, (int)old, null, NullRect, (int)value, null, NullRect);
OnKindChanged(old, value);
}
}
}
protected virtual void OnKindChanged(GraphNodeKind oldkind, GraphNodeKind newkind)
{
//Update the parts, based on the Kind of node this now is
Color first = Color.FromArgb(159, 232, 0);
Color second = Color.White;
switch (newkind)
{
case GraphNodeKind.Start:
{
this.Text = "Start";
this.Background = new GoDrawing(GoFigure.RoundedRectangle);
this.Shape.FillShapeHighlight(first, second);
this.TopLeftMargin = new SizeF(10, 5);
this.BottomRightMargin = new SizeF(10, 5);
UpdatePorts("", "o", "o", "o");
break;
}
case GraphNodeKind.End:
{
this.Text = "End";
this.Background = new GoDrawing(GoFigure.RoundedRectangle);
this.Shape.FillShapeHighlight(first, second);
this.TopLeftMargin = new SizeF(10, 5);
this.BottomRightMargin = new SizeF(10, 5);
UpdatePorts("i", "i", "", "i");
break;
}
case GraphNodeKind.Step:
{
this.Text = "Step";
this.Background = new GoDrawing(GoFigure.Rectangle);
this.Shape.FillShapeHighlight(first, second);
this.TopLeftMargin = new SizeF(10, 5);
this.BottomRightMargin = new SizeF(10, 5);
UpdatePorts("io", "io", "io", "io");
break;
}
case GraphNodeKind.Input:
{
this.Text = "Input";
this.Background = new GoDrawing(GoFigure.Input);
this.Shape.FillShapeHighlight(first, second);
this.TopLeftMargin = new SizeF(20, 4);
this.BottomRightMargin = new SizeF(20, 4);
UpdatePorts("io", "io", "io", "io");
break;
}
case GraphNodeKind.Output:
{
this.Text = "Output";
this.Background = new GoDrawing(GoFigure.Output);
this.Shape.FillShapeHighlight(first, second);
this.TopLeftMargin = new SizeF(20, 4);
this.BottomRightMargin = new SizeF(20, 4);
UpdatePorts("io", "io", "io", "io");
break;
}
case GraphNodeKind.Decision:
{
this.Text = "?";
this.Background = new GoDrawing(GoFigure.Decision);
this.Shape.FillShapeHighlight(first, second);
this.TopLeftMargin = new SizeF(35, 20);
this.BottomRightMargin = new SizeF(35, 20);
UpdatePorts("i", "io", "o", "io");
break;
}
case GraphNodeKind.Read:
{
this.Text = "Read";
this.Background = new GoDrawing(GoFigure.Ellipse);
this.Shape.FillShapeHighlight(first, second);
this.Shape.BrushPoint = new PointF(.3f, .3f);
this.TopLeftMargin = new SizeF(20, 10);
this.BottomRightMargin = new SizeF(20, 10);
UpdatePorts("io", "io", "io", "io");
break;
}
case GraphNodeKind.Write:
{
this.Text = "Write";
this.Background = new GoDrawing(GoFigure.Ellipse);
this.Shape.FillShapeHighlight(first, second);
this.Shape.BrushPoint = new PointF(.3f, .3f);
this.TopLeftMargin = new SizeF(20, 10);
this.BottomRightMargin = new SizeF(20, 10);
UpdatePorts("io", "io", "io", "io");
break;
}
case GraphNodeKind.ManualOperation:
{
this.Text = "Manual \nOperation";
this.Background = new GoDrawing(GoFigure.ManualOperation);
this.Shape.FillShapeHighlight(first, second);
this.TopLeftMargin = new SizeF(20, 10);
this.BottomRightMargin = new SizeF(20, 10);
UpdatePorts("io", "io", "io", "io");
break;
}
case GraphNodeKind.Database:
{
this.Text = "Database";
this.Background = new GoDrawing(GoFigure.Database);
this.Shape.FillShapeHighlight(first, second);
this.Shape.BrushPoint = new PointF(.15f, .55f);
this.Shape.BrushFocusScales = new SizeF(.1f, .1f);
this.TopLeftMargin = new SizeF(10, 30);
this.BottomRightMargin = new SizeF(10, 15);
UpdatePorts("io", "io", "io", "io");
break;
}
default: throw new InvalidEnumArgumentException("newkind", (int)newkind, typeof(GraphNodeKind));
}
}
protected override GoPort CreatePort(int spot)
{
GoPort p = base.CreatePort(spot);
p.Brush = null;
return p;
}
private void UpdatePorts(String t, String r, String b, String l)
{
//TopPort, RightPort, BottomPort, LeftPort
if (t == "")
{
this.TopPort = null;
}
else
{
if (this.TopPort == null) this.TopPort = CreatePort(MiddleTop);
if (this.TopPort != null)
{
this.TopPort.IsValidFrom = t.IndexOf('o') > -1;
this.TopPort.IsValidTo = t.IndexOf('i') > -1;
}
}
if (r == "")
{
this.RightPort = null;
}
else
{
if (this.RightPort == null) this.RightPort = CreatePort(MiddleRight);
if (this.RightPort != null)
{
this.RightPort.IsValidFrom = r.IndexOf('o') > -1;
this.RightPort.IsValidTo = r.IndexOf('i') > -1;
}
}
if (b == "")
{
this.BottomPort = null;
}
else
{
if (this.BottomPort == null) this.BottomPort = CreatePort(MiddleBottom);
if (this.BottomPort != null)
{
this.BottomPort.IsValidFrom = b.IndexOf('o') > -1;
this.BottomPort.IsValidTo = b.IndexOf('i') > -1;
}
}
if (l == "")
{
this.LeftPort = null;
}
else
{
if (this.LeftPort == null) this.LeftPort = CreatePort(MiddleLeft);
if (this.LeftPort != null)
{
this.LeftPort.IsValidFrom = l.IndexOf('o') > -1;
this.LeftPort.IsValidTo = l.IndexOf('i') > -1;
}
}
}
//if the Label is not visible or if the view has a small DocScale,it's handy to be able to see the name of the lane
public override String GetToolTip(GoView view)
{
return this.Text;
}
}
I would like a class to create “STEP”, “START” object with an image for example: