First of all, a GoPalette is just a GoView with some special behavior. It displays the GoObjects you Add to the view.Document.
Use the GoPalette class. Into the palette’s Document just add instances of each kind of node that you want your users to be able to drag and drop. You can control the Orientation and GridCellSize and alignment, as well as whether the items are sorted and in what order with the Sorting property. You can even turn off the automatic positioning of items in the palette’s document by setting the AutomaticLayout property to false. In addition, all of the standard GoView properties apply, although many have already been turned off by calling SetModifiable(false), so that users do not modify the palette or its contents.
When the user drops a GoObject into a view, the view’s document’s GoDocument.CopyFromCollection method is called to copy the object into the document. If you need to adjust the dropped object(s) in some way, you should add a GoView.ExternalObjectsDropped event handler to modify the object(s) in the GoView.Selection.
----------------
Here's the code that adds the parts to the Flowcharter sample GoPalette:
[code]
private void InitializeCatalog() {
GoComment c = new GoComment();
c.Text = "Enter your comments here";
myPalette.Document.Add(c);
GraphNode n;
n = new GraphNode(GraphNodeKind.Start);
myPalette.Document.Add(n);
n = new GraphNode(GraphNodeKind.Step);
myPalette.Document.Add(n);
...
}
[/code]
The red code adds a GoComment... the blue adds a "Start" GraphNode.
The GraphNode is a good example here, since it is a single node that knows how to "look" like multiple different types of nodes (although in this case, that happens to be a hard-coded list of types). The node (or nodes) you define in your app have to be extensible to allow adding new ones from data. That might be "a node with an icon of a router box", where the only customizable attribute is the icon.
Again, if you look at GraphNode, here is the code that makes it be a "Start" node...
[code]
// (note: this may be v3 specific code here)
case GraphNodeKind.Start: {
this.Text = "Start";
this.Background = new GoDrawing(GoFigure.RoundedRectangle);
((GoDrawing)(this.Background)).FillShapeHighlight(first, second);
this.TopLeftMargin = new SizeF(10, 5);
this.BottomRightMargin = new SizeF(10, 5);
UpdatePorts("", "o", "o", "o");
break;
}
[/code]
The Label, Background, Fill, Margins and Port locations are all "attributes" of the node that might be stored in a data file that defined what sorts of objects to add to the palette. There are certainly others you can think of ... pen color, brush color, internal part ID, options that control the Node's behavior after it is dropped in the view... etc.