initializing Color arrays...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I was wondering if someone could tell me the exact syntax for initializing a Color array.

I thought it would be something like below, but I check them and its says they're empty

Color colors[] = {Color::Black,Color::Blue,Color::Black}

It makes the array and puts it at a length of 3 but it doesn't put the colors in the array? Once I figured out that it was creating the slots of the array I could easily set each slot, but I figure I must be doing something wrong in the initialization.
 
I think that you create colours from three of its static methods, FromArgb, FromKnownColor and FromName. Otherwise you get the value of 0

A few ways you can try

1) Convert to intege

int clr[] =
Color::Red.ToArgb(),
Color::Green.ToArgb(),
Color::Blue.ToArgb()
}

this->BackColor = Color::FromArgb(clr[0])

2) Get from a known colour, which is what you're after by the look of i

KnownColor clr[] =
KnownColor::Red
KnownColor::Green
KnownColor::Blu
}

this->BackColor = Color::FromKnownColor(clr[0])

3) Define your own colou

int clr[] =
Color::FromArgb(255,0,0).ToArgb(),
Color::FromArgb(0,255,0).ToArgb(),
Color::FromArgb(0,0,255).ToArgb(
}

this->BackColor = Color::FromArgb(clr[0])
 
Back
Top