C# ContextMenuStrip 项属性!

发布于 2024-09-05 10:16:01 字数 445 浏览 0 评论 0原文

如何根据值设置和获取上下文菜单条中项目的文本和/或背景的颜色值?

这段代码正确吗?

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

但我找不到获取颜色值的方法!

我这样做了:

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

但它不起作用!!!!

还如何根据项目字符串值获取或/和设置其他属性(例如“这是一个项目”)?

干杯

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怂人 2024-09-12 10:16:01

“键”是 ToolStripItem.Name 属性。请尝试以下操作:

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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文