如何找到带有名称的工具tripmenuItem [英] How to find toolstripmenuItem with name

查看:107
本文介绍了如何找到带有名称的工具tripmenuItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将menuStrip1项的visible属性设置为false

I have set visible property of my menuStrip1 items to false as

foreach (ToolStripMenuItem itm in menuStrip1.Items)
{
    itm.Visible = false;
}

现在我知道menustrip1的toolStripMenuItem and dropDownItem的名称.如何激活所需的toolStripMenuItem and dropDownItem.

Now I know the Names of toolStripMenuItem and dropDownItem of the menustrip1. How to can I activate the required toolStripMenuItem and dropDownItem.

我有

string mnItm = "SalesToolStripMenuItem";
string ddItm = "invoiceToolStripMenuItem";

现在我要为这两个(toolStripMenuItem and dropDownItem)项目设置visible true.我怎样才能做到这一点?我只知道那些名字.

Now I want to set visible true to these two(toolStripMenuItem and dropDownItem) items. How can I do that? I know those names only.

推荐答案

您应该尝试以下方法:

string strControlVal ="somecontrol"; //"SalesToolStripMenuItem" or "invoiceToolStripMenuItem" in your case
foreach (ToolStripMenuItem item in menuStrip1.Items)
{
     if (strControlVal == item.Name)
     { 
        item.Visible = false;
     }
}

根据需要在需要时初始化strControlVal字符串.

Initialize strControlVal string on your discretion where you need it.

这篇关于如何找到带有名称的工具tripmenuItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆