I’m using GoExpress 2.6.2.2.
The UserObject doesn’t have anything to do with color, it’s just a property left unused by our code so that you can associate your own object with the node.
What node class are you using?
Ok. I’m sure I’ve written a lot of code to convert color FromArgb(…) etc… <?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
May I use the Brush property?
I've created a class TreeAppNode that extends GoBasicNode
public class TreeAppNode : GoBasicNode {
/* BEFORE
public TreeAppNode() {
this.Port.AddObserver(this);
this.LabelSpot = GoObject.Middle;
this.Editable = true;
this.Text = "";
this.Label.Editable = false;
this.Resizable = false;
this.MiddleLabelMargin = new SizeF(30, 15);
this.UserObject = NewVersion.nuovoColore; //global variable with type Color
}
*/
//NOW
public TreeAppNode(SolidBrush what_color)
{
this.Port.AddObserver(this);
this.LabelSpot = GoObject.Middle;
this.Editable = true;
this.Text = "";
this.Label.Editable = false;
this.Resizable = false;
this.MiddleLabelMargin = new SizeF(30, 15);
this.Brush = what_color;
}
Due to a business logic I’ve nodes with different colors on the canvas and it’s all OK when I add them to the goView.
But when the user makes a link between two nodes in the LinkCreated event handler I need to set the same color of the father node to the child one.
What’s the error in the code I append here?
private void goViewGraph_LinkCreated(object sender, GoSelectionEventArgs e)
{
TreeAppNode nFather = (TreeAppNode)((GoLink)e.GoObject).FromNode;
TreeAppNode nSon = (TreeAppNode)((GoLink)e.GoObject).ToNode;
Brush colFather = nFather.Brush;
nSon.Brush = colFather;
goViewGraph.Document.InvalidateViews();
goViewGraph.UpdateView();
}
I can’t see any change on the screen.
Yes, the Brush property is the right thing to use.
You shouldn’t have to call InvalidateViews or UpdateView. Go objects are smart enough to repaint themselves when a property changes.
And one important rule… you can’t change a Pen or a Brush after it has been set into a GoObject. You must create a new pen/brush.
Hi Jake, sorry to come back this issue.
How to create a new pen/brush? I get stuck with several nodes, if I change the color of a node, the other nodes’ colors are also changed, even the original node on palette :(