VB.NET ToolsStrip控件 [英] VB.NET ToolsStrip Control
本文介绍了VB.NET ToolsStrip控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个工具条控件.首先,我填充工具栏按钮.
在该按钮单击事件中,我在
下填充了工具条标签
特定按钮.当我再次单击按钮时,它应该清除
先前加载的标签并重新加载.
I have a toolstrip control. First I Populate Toolstrip button.
In that button click event i populate toolstrip labels under
particular button. When i click the button again it should clear
previously loaded labels and load freshly.
For Each ctl As ToolStripItem In ToolStrip1.Items
If TypeOf (ctl) Is ToolStripLabel Then
ToolStrip1.Items.Remove(ctl)
End If
Next
但我发现以下异常.请帮我解决这个问题
集合已修改;枚举操作可能不会执行.
But i found the following exception. Please help me to solve this issue
Collection was modified; enumeration operation may not execute.
推荐答案
不是每次尝试都使用for
循环,而将计数器计数为ToolStrip1.Items.Count
.使用对于每个循环"时,无法修改集合(删除项目).
另外,如果您删除项目,请考虑从Items.Count倒数到0(步骤-1)
Instead of using for each try usingfor
loop with a counter counting toToolStrip1.Items.Count
. When using For each loops you cannot modify the collection (delete items).
Addition, if you delete items consider counting backwards down from Items.Count to 0 (step -1)
您好
我是VB.net的新手
所以请解释怎么做
我是这样的但这没有效果
Hi
I am new to VB.net
so please explain how to do it
I do it like this. But it has no effect
For i = ToolStrip1.Items.Count To 1 Step -1
Dim ctl As ToolStripItem
If TypeOf (ctl) Is ToolStripLabel Then
ToolStrip1.Items.Remove(ctl)
End If
Next
请帮助....
Please Help....
For i = ToolStrip1.Items.Count - 1 To 1 Step -1
Dim item As ToolStripLabel = TryCast(ToolStrip1.Items(i), ToolStripLabel)
ToolStrip1.Items.Remove(item)
Next
这篇关于VB.NET ToolsStrip控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文