0

am reading this tutorial http://chalaki.com/how-to-program-msagl-glee-to-create-hierarchical-graph-layouts/519/

using the code sample.

enter image description here

am trying to make the attributes dynamic (i want to be able to load the attributes from a database later)

i have tried

string dColor = "Red"; 
string dShape = "Diamond";

Microsoft.Glee.Drawing.Node n2 = graph.FindNode(strNode2);
n2.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.dColor;
n2.Attr.Shape = Microsoft.Glee.Drawing.Shape.dShape;

but its not working, how do i do this or even read about doing this dynamically?

[ANSWER] Am not sure if this is the best way,but it works.

--For Colors i did

using mColor = Microsoft.Msagl.Drawing.Color;
using sColor = System.Drawing.Color;

sColor c = sColor.FromName("Red");
graph.FindNode("test1").Attr.FillColor = new mColor(c.A,c.R,c.G,c.B);

--For the shape i did

 graph.FindNode("test1").Attr.Shape = (Shape)
 (int)Enum.Parse(typeof(Shape),"Diamond");

where "test1","diamond" and "Red" values come from the database.

Law
  • 129
  • 1
  • 3
  • 10

1 Answers1

1

A Color is not a string.

Microsoft.Glee.Drawing.Node n2 = graph.FindNode(strNode2);
var someColor = System.Drawing.Color.Red;
n2.Attr.Fillcolor = someColor;

If you will be storing the colors in the database, you can use one of the static methods on Color:

string dColor = "Red"; 
n2.Attr.Fillcolor = Color.FromName(dColor);

If you will not stick to the named colors, there is also Color.FromArgb(int);

EDIT

Looks like they are using a different Color class from the one in System.Drawing here. I found an example on the MSDN forums:

string color = "Red";
var cvtColor = new ColorConverter();
var sysColor = cvtColor.ConvertFromString(color);
n2.Attr.Fillcolor = new Microsoft.Msagl.Drawing.Color(sysColor.R, sysColor.B, sysColor.G);

There is some example code on GitHub:

n2.Attr.Fillcolor = Microsoft.Msagl.Drawing.Color.Magenta;
Laoujin
  • 9,962
  • 7
  • 42
  • 69
  • i get an Error : CS0029 Cannot implicitly convert type 'System.Drawing.Color' to 'Microsoft.Msagl.Drawing.Color' – Law Jun 04 '17 at 12:49
  • I hope you have an IDE where you can easily discover how this `Microsoft.Msagl.Drawing.Color` works. If not, you can use ILSpy or dotPeek. I've updated my answer. – Laoujin Jun 04 '17 at 13:00