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
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With