问题ToolStripSeparator [英] problem with ToolStripSeparator

查看:431
本文介绍了问题ToolStripSeparator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工具条。对于这个工具条,我加入 ToolStripSplitButton 并为此的 ToolStripSplitButton ,我加入工具条的物品,其中包括的 ToolStripSeparator 。在工具条项的单击事件,我从 ToolStripSplitButton 使用下面code下拉列表。

I have a toolstrip. For this toolstrip, I am adding ToolStripSplitButton and for this ToolStripSplitButton, I am adding toolstrip items, including ToolStripSeparator. In the click event of the toolstrip items I am retrieving items from the ToolStripSplitButton dropdown using below code.

 ToolStripDropDown tditems = ((System.Windows.Forms.ToolStripDropDownItem)(items[0])).DropDown;
foreach (ToolStripMenuItem item in tditems.Items)
{
//something here
}

随着下拉项具有两个工具条的项目和 ToolStripSeparator 在运行时,它给下面的错误。

As the dropdown items have both toolstrip items and ToolStripSeparator at runtime, it is giving following error.

信息:无法施放   类型的对象   System.Windows.Forms.ToolStripSeparator   输入   System.Windows.Forms.ToolStripMenuItem。

Additional information: Unable to cast object of type 'System.Windows.Forms.ToolStripSeparator' to type 'System.Windows.Forms.ToolStripMenuItem'.

任何人可以帮助我吗?

感谢

推荐答案

如果您使用的是.NET 3.5,你可以使用的 OfType 扩展方法如下:

If you are using .NET 3.5, you could use the OfType extension method as follows.

foreach (var item in tditems.Items.OfType<ToolStripMenuItem>())
{
    // something here
}

这篇关于问题ToolStripSeparator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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