如何从表单中清除控件 - 需要帮助 [英] How to clear controls from a form - Help Needed
问题描述
我有一个表单,我以编程方式生成一些复选框和标签。
稍后,当我想要绘制具有不同数据的表单时,我想清除
先前创建的项目,然后放入一些新项目。
在我的代码中,我正在执行以下操作:
每个ctrl在tpMain中.Controls
如果TypeOf(ctrl)是CheckBox那么
如果ctrl.Name.StartsWith(" chkS")那么
ctrl.Visible = False
ctrl.Dispose()
结束如果
结束如果
结束如果
下一页
我发现的是,在某些情况下,我知道控制器已经受到上述循环影响的
停留在表格上并且没有被制作
看不见然后被处置。
是否有一种确定的消除控制方法而不是处置的方法
方法,大概并不总是取消控制的任何原因
原因??
Siv
-
Martley,英国伍斯特附近
I have a form that I programmatically generate some check boxes and labels on.
Later on when I want to draw the form with different data I want to clear
the previously created items and then put some new ones on.
In my code I am doing the following:
For Each ctrl In tpMain.Controls
If TypeOf (ctrl) Is CheckBox Then
If ctrl.Name.StartsWith("chkS") Then
ctrl.Visible = False
ctrl.Dispose()
End If
End If
End if
Next
What I am finding however is that in some cases controls that I know have
been affected by the above loop are staying on the form and not being made
invisible and then being disposed.
Is there a sure fire method of removing the controls rather than the dispose
method which presumably is not always removing the control for whatever
reason??
Siv
--
Martley, Near Worcester, UK
推荐答案
使用额外的
额外控件可以更容易/更简单/更可靠。当用户需要使用另一组控件 -
而不是创建一组全新的控件时,只需调出额外的
表单并隐藏主表单 - 或者如果它甚至不做任何事情
与主要表格。只需让它继续运行。
Rich
***通过Developersdex发送 http://www.developersdex.com ***
It would be much easier/simpler/reliable to have an extra form with the
extra controls. When a user needs to use the other set of controls -
instead of creating a whole new set of controls just bring up the extra
form and hide the main form - or if it even matters don''t do anything
with the main form. Just leave it running.
Rich
*** Sent via Developersdex http://www.developersdex.com ***
我做不到因为重绘之间的复选框数量差别很大,所以没有固定的布局。在一组数据上,我可能只需要b $ b需要在另一组上显示2个复选框,可能是20或30.我正在尝试
避免成千上万的开销只有
创建它们,因为我需要它们然后当我完成它们时再次破坏
它们。
我认为问题在于,当我想要它时,处理方法并不总是决定
处理并且可能正在等待系统安静
down在执行请求之前。
我真的需要一个Ctrl.delete类型的命令。
Siv
-
Martley,英国伍斯特附近
Rich P写道:
I can''t do that because the amount of check boxes differs dramatically
between redraws, there isn''t a fixed layout. On one set of data I may only
need to show 2 check boxes on another ther may be 20 or 30. I am trying to
avoid the overhead of having thousands of controls on the forma nd only
create them as I need them and then when I have finished with them destroy
them again.
The problem i think is tha the dispose method doesn''t always decide to
dispose when I want it to and is probably waiting for the system to quieten
down before actioning the request.
I really need a Ctrl.delete type comand.
Siv
--
Martley, Near Worcester, UK
"Rich P" wrote:
使用
额外控件获得额外的表单会更容易/更简单/更可靠。当用户需要使用另一组控件 -
而不是创建一组全新的控件时,只需调出额外的
表单并隐藏主表单 - 或者如果它甚至不做任何事情
与主要表格。只需让它继续运行。
Rich
***通过Developersdex发送 http://www.developersdex.com ***
It would be much easier/simpler/reliable to have an extra form with the
extra controls. When a user needs to use the other set of controls -
instead of creating a whole new set of controls just bring up the extra
form and hide the main form - or if it even matters don''t do anything
with the main form. Just leave it running.
Rich
*** Sent via Developersdex http://www.developersdex.com ***
Siv写道:
Siv wrote:
我不能这样做,因为复选框的数量差别很大
重绘之间,没有固定的布局。在一组数据上,我可能只需要b $ b需要在另一组上显示2个复选框,可能是20或30.我正在尝试
避免成千上万的开销只有
创建它们,因为我需要它们然后当我完成它们时再次破坏
它们。
我认为问题在于,当我想要它时,处理方法并不总是决定
处理并且可能正在等待系统安静
down在执行请求之前。
我真的需要一个Ctrl.delete类型的命令。
Siv
I can''t do that because the amount of check boxes differs dramatically
between redraws, there isn''t a fixed layout. On one set of data I may only
need to show 2 check boxes on another ther may be 20 or 30. I am trying to
avoid the overhead of having thousands of controls on the forma nd only
create them as I need them and then when I have finished with them destroy
them again.
The problem i think is tha the dispose method doesn''t always decide to
dispose when I want it to and is probably waiting for the system to quieten
down before actioning the request.
I really need a Ctrl.delete type comand.
Siv
试试这个:
创建一个面板,放置动态控件。
完成后那些控件,原始面板应该有一个变量
。使用Clear方法去除你动态创建的所有
控件。
新信息。
希望这有帮助
LS
Try this:
Create a panel onto which you will place your dynamic controls.
When you are finished with those controls, you should have a variable
for the original panel. Use the Clear method to get rid of all the
controls you created dynamically.
You now should have a blank panel upon which you can add controls with
new info.
Hope this helps
LS
这篇关于如何从表单中清除控件 - 需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!