views:

359

answers:

1

Hello,

how to set and get the colors value to text and/or Background of an item in a context menu strip based on the value?

is this code right way?

ContextMenuStrip1.Items.Add("this is an item").BackColor = Color.FromArgb(255, 179, 179);

but I can not find out a way to get the color value!

I did this:

int i = ContextMenuStrip1.Items.IndexOfKey("this is an item");
Color c = ContextMenuStrip1.Items[i].BackColor; // I get error in here!

but it is not working !!!!

also how to get or/and set other properties based on the item string value (example "this is an item")?

cheers

+1  A: 

the "key" is the ToolStripItem.Name property. Try the following:

ContextMenuStrip ContextMenuStrip1 = new ContextMenuStrip();
var item = ContextMenuStrip1.Items.Add("this is an item");
item.BackColor = Color.FromArgb(255, 179, 179);
item.Name = "key";

int i = ContextMenuStrip1.Items.IndexOfKey("key");
Color c = ContextMenuStrip1.Items[i].BackColor;
Mark Heath
Thanks, that was perfect :-)
Data-Base