C #, how to get all the colors of objects coexist System.Drawing.Color into an array

Scenes

When required to generate a set of a plurality of curves, a randomly selected color from the color array, at least one hundred or more colors.

140 kinds of colors and comes System.Drawing.Color

 

 

So how it comes out and there is a color of an object in the array.

Note:

Blog home page:
https://blog.csdn.net/badao_liumang_qizhi
public concern number
overbearing program ape
acquisition-related programming e-books, tutorials and free downloads push

achieve

// for accessing the object color extraction 
List <Color> = the colorList new new List <Color> ();
 // get all members of the public by GetMember 
the foreach ( var Item in  typeof (Color) .GetMembers ()) 
      { 
       // and take only property Color properties are known, and some boolean attribute byte remove attributes (ABGR IsKnownColor Name, etc.) 
          IF (item.MemberType == System.Reflection.MemberTypes.Property && System.Drawing.Color.FromName 

(Item .name) .IsKnownColor == to true ) 
              { 
                  Color Color = System.Drawing.Color.FromName (item.name); 
                  colorList.Add (Color);
               } 
        }
// turn into an array 
Color [] colors = colorList.ToArray () ;

At this point you can see the color of the object is acquired by an array:

 

 

 

Guess you like

Origin www.cnblogs.com/badaoliumangqizhi/p/12094767.html