Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# ContextMenuStrip item properties !

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

like image 516
Data-Base Avatar asked Dec 03 '25 19:12

Data-Base


1 Answers

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;
like image 82
Mark Heath Avatar answered Dec 06 '25 08:12

Mark Heath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!