有一个!toolstrip1 上面 有toolstripbutton 还有toolstriplabel 还有
toolStripSeparator我只想遍历到button 怎么弄啊?
string[] a = GlobalClass.userinfo.Qx;
foreach (ToolStripButton mi in toolStrip1.Items)
{
mi.Enabled = false;
for (int i = 0; i < a.Length; i++)
{
if (a[i] == mi.Tag.ToString())
{
mi.Enabled = true;
i = a.Length;
}
} }这么写 报错 无法将toolstriplabel 强制转换为toolstripbutton
求解释帝!!
toolStripSeparator我只想遍历到button 怎么弄啊?
string[] a = GlobalClass.userinfo.Qx;
foreach (ToolStripButton mi in toolStrip1.Items)
{
mi.Enabled = false;
for (int i = 0; i < a.Length; i++)
{
if (a[i] == mi.Tag.ToString())
{
mi.Enabled = true;
i = a.Length;
}
} }这么写 报错 无法将toolstriplabel 强制转换为toolstripbutton
求解释帝!!
if (mi.GetType() == typeof(ToolStripButton))foreach (ToolStripItem mi in toolStrip1.Items)
{
if (mi.GetType() == typeof(ToolStripButton))
{
mi.Enabled = false;
for (int i = 0; i < a.Length; i++)
{
if (a[i] == mi.Tag.ToString())
{
mi.Enabled = true;
i = a.Length;
}
} }
}
或is 判断类型
foreach (ToolStripItem mi in toolStrip1.Items)
{
mi.Enabled = false;
if (mi is ToolStripButton)
{
Console.WriteLine("Button");
}
}
我强制转换了下!!!foreach (object mi in toolStrip1.Items)
{
if (mi is ToolStripButton)
{
((ToolStripButton)mi).Enabled = false;
for (int i = 0; i < a.Length; i++)
{
if (a[i] == ((ToolStripButton)mi).Tag.ToString())
{
((ToolStripButton)mi).Enabled = true;
i = a.Length;
}
}
}
}
ms = (System.Windows.Forms.ToolStripMenuItem)toolstrip1.Items[];
强制转换