foreach (Control control in this.Controls) //遍历控件 { if (control is Button) { if (control.Name =="btnOK") { control.Enabled = false; control.Visible = false; } } }
foreach (ToolStripMenuItem toolMenuItem in this.MainMenuStrip.Items) //遍历菜单栏 { foreach (ToolStripItem toolScriptItem in toolMenuItem.DropDownItems) { if (toolScriptItem is ToolStripMenuItem)
{ if (toolScriptItem.Name == "ToolItem_Calc") { toolScriptItem.Enabled = false; //使此项不能选(单击无效) toolScriptItem.Visible = false; //使此项不可用(看不见) } } } }
遍历控件 和 菜单项
最新推荐文章于 2023-05-15 16:04:03 发布