Generate random dark colors?

Nov 27, 2013 at 10:57 AM
Hi! Nodexl's background is white, how to generate random dark colors by using API?
Nov 27, 2013 at 3:26 PM
Edited Nov 28, 2013 at 4:36 AM
You could do something like this. I'm typing this off the top of my head, but it should give you the general idea.
const Int32 MaximumColorComponentValue = 50;
Random random = new Random();

nodeXLControl.GraphDrawer.BackColor = System.Drawing.Color.FromArgb(
  random.Next(MaximumColorComponentValue),
  random.Next(MaximumColorComponentValue),
  random.Next(MaximumColorComponentValue)
  );
-- Tony
Nov 28, 2013 at 4:03 AM
oh! I want to generate different random dark colors to draw vertex!
Nov 28, 2013 at 4:16 AM
By the way, I wrote this code--"vertex.SetValue( ReservedMetadataKeys.PerVertexImage,new System.Windows.Media.Imaging.BitmapImage(new Uri("d:\1.jpg") ) );" But the vertex did not turn into a picture. What's wrong with it?
Nov 28, 2013 at 4:21 AM
Edited Nov 28, 2013 at 4:22 AM
You said "background," Doug.

But the principal for vertices is the same. Again, I'm typing this without actually trying it, so caveat emptor:
const Int32 MaximumColorComponentValue = 50;
Random random = new Random();

foreach (IVertex vertex in nodeXLControl.Graph.Vertices)
{
  System.Drawing.Color randomDarkColor = System.Drawing.Color.FromArgb(
    random.Next(MaximumColorComponentValue),
    random.Next(MaximumColorComponentValue),
    random.Next(MaximumColorComponentValue)
    );

  vertex.SetValue(ReservedMetadataKeys.PerColor, randomDarkColor);
}
-- Tony
Nov 28, 2013 at 4:27 AM
Didn't you get a compiler error with your BitmapImage code? "d:\1.jpg" contains an illegal escape sequence.

-- Tony
Nov 28, 2013 at 3:55 PM
Edited Nov 28, 2013 at 4:03 PM
But apart from your syntax mistake (just a typo in CodePlex?), you also have to set the vertex shape:
vertex.SetValue(ReservedMetadataKeys.PerVertexShape, VertexShape.Image);
-- Tony