Change Color Node

I’m using GoExpress 2.6.2.2.

I've a Node whose color is set when it's added to the goView.
How is it possible to change its color programmatically at runtime?
Here is my code:
node1.UserObject = colorX;
goView1.Document.InvalidateViews();
I'm sure that the UserObject Value is really modified (by debug and by saving the graph and reopening it as XML it appears correct!), but I don't see any change on the screen.
How can I obtain the refresh of the goView1?
Thanks in advance.

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 :(