首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

遍历菜单报错,该如何处理

2012-09-25 
遍历菜单报错无法将类型为“System.Windows.Forms.ToolStripSeparator”的对象强制转换为类型“System.Window

遍历菜单报错
无法将类型为“System.Windows.Forms.ToolStripSeparator”的对象强制转换为类型“System.Windows.Forms.ToolStripMenuItem”。  

遍历二级菜单 中间有分割线就报这个错误 如何解决?

[解决办法]
foreach (ToolStripItem item in menuStrip1.Items)
{

if (item is ToolStripMenuItem)
{
ToolStripMenuItem x = item as ToolStripMenuItem ;
MessageBox.Show(x.Text);
EnumerMenu(x);
}
}

热点排行