P
P
phpshka2019-02-25 13:13:44
C++ / C#
phpshka, 2019-02-25 13:13:44

How to loop through contextmenustrip (items collection) and change them in c#?

Good afternoon!
Connoisseurs, please tell me how you can iterate over the elements of the contextmenustrip.items collection, if this collection has two types "ToolStripMenuItem", "ToolStripSeparator"?
At the same time, you need to reset the picture for certain elements according to the condition ...
I tried like this, but I can't change the element.

foreach (var subItem in contextMenuForm.Items)
{
    if (subItem != e.ClickedItem)
    {                   
    //subItem.Image = null;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bogdan, 2019-02-25
@phpshka

For example like this

foreach (ToolStripItem subItem in contextMenuForm.Items)
{
   if (subItem != e.ClickedItem)
   {
      subItem.Image = null;
   }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question