关于删除动态控件的认真讨论 [英] Serious discussion about removing dynamically controls

查看:58
本文介绍了关于删除动态控件的认真讨论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我从昨天开始一个关于讨论的新帖子(或者对于我们中的一些人来说今天早上是b $ b)。这是一个关于从面板中动态删除

控件的讨论还不是很好。

它是从我的一个例子开始的,这远远不是完整的并且打字

错误,但基本上它有意义显示删除控件

可逆是最好的方法。


这是一个几个星期前在这个新闻组中,我们可以在

讨论中说出结论(但在新闻组中是什么)。该方法由

Armin提供。我发现它很棒,从那时起我称之为方法

Armin。


杰克完全不同意这种方法,并在一段时间后做了贡献

一些代码。


因此我在这个新线程中将这两个代码发送到这个新闻组。我认为

专业谈论这件事很好。所以这不是代码Cor,Nick,

Armin或Jack。只是方法反向下一循环,反对while

end while循环用于动态删除控件。


我不想从我的+关于方法的点数开始,也许我会

给出,但是我希望它会自动出现在这个新闻组中


杰克给我的一些贡献的代码,因为我没有

知道removeAT存在。但是我总是按照相同的方式做我做的事情。所以我怀疑我是否会使用它,但是我的确使用了

" removeAT" (我认为它更好)。请不要开始讨论

。问题是while while while反对逆转下一步。


" while end While"

Dim idx As Integer

idx = 0

虽然idx< Me.Panel1.Controls.Count''在界限内

如果TypeOf Me.Panel1.Controls.Item(idx)是标签那么

Me.Panel1.Controls.RemoveAt (idx)

否则

idx = idx + 1''否则提前到下一个控制

结束如果

结束时

-----------------

" For index Next reversal"

Dim idx As Integer

For idx = Me.Panel1.Controls.Count - 1 To 0 Step -1

If TypeOf Me.Panel1.Controls.Item(idx)Is标签然后

Me.Panel1.Controls.RemoveAt(idx)

结束如果

下一页

我希望这个贡献一些东西

Cor


Hi,
I start a new thread about a discussion from yesterday (or for some of us
this morning). It was a not so nice discussion about dynamically removing
controls from a panel or what ever.
It started by an example from me, that was far from complete and with typing
errors, but basically it had the meaning to show that removing controls
reversible was the nicest method.

This was a lets say conclusion (but what is that in a newsgroup) in a
discussion some weeks ago in this newsgroup. The method was contributed by
Armin. I found it brilliant and since that time I call this the method
Armin.

Jack did totally disagree with this method and did after a while contribute
some code.

Therefore I send both code''s to this newsgroup in this new thread. I think
it is good to talk professionally about it. So it is not the code Cor, Nick,
Armin or Jack. Just the method "reverse For next loop", against the "While
end while loop" for removing controls dynamically.

I don''t want to start with my + of - points about the methods, maybe I will
give that, but I hope that it will come automatically in this newsgroup

The code that Jack has given some contribution for me, because I did not
know "removeAT" exist. But I always do the things that I do plus in the same
way minus. So I doubt if I will use it, but for the example I did use
"removeAT" (I think it is nicer). Please don''t start a discussion about
that. The question is the "While end while" against reversal "For next".

"While end While"
Dim idx As Integer
idx = 0
While idx < Me.Panel1.Controls.Count '' while in bounds
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
Else
idx = idx + 1 '' otherwise advance to next control
End If
End While
-----------------
"For index Next reversal"
Dim idx As Integer
For idx = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
End If
Next
I hope this contribute something
Cor


推荐答案

我赞成我倾向于使用的反转代码很多,因为它更干净

并且通常可以避免你遇到问题。


-

问候 - 一手男人


作者:Fish .NET&保持.NET

======================================= ==

此帖子按原样提供。没有保证,

并且不授予任何权利。

" Cor" < no*@non.com>在留言中写道

news:3f *********************** @ reader20.wxs.nl ...
I favour the reversal code which I tend to use a lot because it''s cleaner
and generally saves you getting into problems.

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...

我从昨天(或今天早上为我们中的一些人)开始讨论讨论。这是一个关于从面板动态删除
控件的讨论还不是很好。
它是从我的一个例子开始的,这远远不是完整的并且有
输入错误,但基本上它有意义表明删除控件
可逆是最好的方法。

这是一个让我们说的结论(但在新闻组中是什么)在讨论中几个星期前在这个新闻组。该方法由Armin提供。我发现它很棒,从那时起我称之为方法
Armin。

杰克完全不同意这种方法,并在一段时间后做了
贡献了一些代码。

因此,我在这个新主题中将这两个代码发送到这个新闻组。我认为专业谈论这件事很好。所以这不是代码Cor,
Nick,Armin或Jack。只是方法反向下一个循环,对着While
end while loop,动态删除控件。

我不想从关于方法的点数开始,也许我会给b $ b,但是我希望它会自动出现这个新闻组

杰克为我做了一些贡献的代码,因为我没有知道removeAT。存在。但我总是按照
相同的方式做我做的事情。所以我怀疑我是否会使用它,但是我的确使用了
removeAT的例子。 (我认为它更好)。请不要开始讨论这个问题。问题是while while while反对逆转下一步。

虽然结束时
Dim idx为整数
idx = 0
而idx< Me.Panel1.Controls.Count''在界限内
如果TypeOf Me.Panel1.Controls.Item(idx)是标签然后
Me.Panel1.Controls.RemoveAt(idx)
Else
idx = idx + 1''否则前进到下一个控件
结束如果
结束时
-----------------
For index Next reversal
Dim idx As Integer
对于idx = Me.Panel1.Controls.Count - 1到0步-1
如果TypeOf Me.Panel1.Controls .Item(idx)是标签然后
Me.Panel1.Controls.RemoveAt(idx)
结束如果
下一页
我希望这会贡献一些东西
Cor



ACK(我假装是Herfried ......我希望)


我唯一可能会改变的是


Do While ...循环


而不是基本上是... We ...循环。


Charles

One Handed Man < TE *************************** @ BTOpenworld.com>写在

消息新闻:ur ************** @ TK2MSFTNGP10.phx.gbl ...
ACK (that''s me pretending to be Herfried ... I wish)

The only thing I would probably change is

Do While ... Loop

instead of what is essentially a While ... Wend loop.

Charles
"One Handed Man" <te***************************@BTOpenworld.com> wrote in
message news:ur**************@TK2MSFTNGP10.phx.gbl...
我赞成反转代码我倾向于使用很多,因为它更干净
并且通常可以避免你遇到问题。

-
问候 - 一个手持人

作者:Fish .NET&保持.NET
========================================= 并且不赋予任何权利。

" Cor" < no*@non.com>在消息中写道
新闻:3f *********************** @ reader20.wxs.nl ...
I favour the reversal code which I tend to use a lot because it''s cleaner
and generally saves you getting into problems.

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...

我从昨天开始一个关于讨论的新帖子(或者今天早上我们的一些b $ b)。这是一个关于动态
从面板中移除控件的讨论还不是很好。
它是从我的一个例子开始的,这远远不是完整的并且带有
Hi,
I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever.
It started by an example from me, that was far from complete and with


打字

错误,但基本上它有意义表明删除控件
可逆是最好的方法。

这是一个让我们说的结论(但那是什么几周前在这个新闻组中的一个新闻组中。该方法由Armin提供
。我发现它很精彩,从那时起我称之为方法
Armin。

杰克完全不同意这种方法,过了一段时间
errors, but basically it had the meaning to show that removing controls
reversible was the nicest method.

This was a lets say conclusion (but what is that in a newsgroup) in a
discussion some weeks ago in this newsgroup. The method was contributed by Armin. I found it brilliant and since that time I call this the method
Armin.

Jack did totally disagree with this method and did after a while


贡献

一些代码。

因此我在这个新主题中将这两个代码发送到这个新闻组。我认为专业谈论这件事很好。所以它不是代码Cor,
some code.

Therefore I send both code''s to this newsgroup in this new thread. I think it is good to talk professionally about it. So it is not the code Cor,


Nick,


Nick,

Armin或Jack。只是方法反向下一个循环,反对
" while end while循环"动态删除控件。

我不想从关于方法的点数开始,也许我
Armin or Jack. Just the method "reverse For next loop", against the "While end while loop" for removing controls dynamically.

I don''t want to start with my + of - points about the methods, maybe I


尽管如此,但我希望它会自动出现在这个新闻组中。

杰克为我做出了一些贡献的代码,因为我没有知道removeAT。存在。但是我总是在
give that, but I hope that it will come automatically in this newsgroup

The code that Jack has given some contribution for me, because I did not
know "removeAT" exist. But I always do the things that I do plus in the


相同的

减去方法中做我做的事情。所以我怀疑我是否会使用它,但是我的确使用了
removeAT的例子。 (我认为它更好)。请不要开始讨论这个问题。问题是while while while反对逆转下一步。

虽然结束时
Dim idx为整数
idx = 0
而idx< Me.Panel1.Controls.Count''在界限内
如果TypeOf Me.Panel1.Controls.Item(idx)是标签然后
Me.Panel1.Controls.RemoveAt(idx)
Else
idx = idx + 1''否则前进到下一个控件
结束如果
结束时
-----------------
For index Next reversal
Dim idx As Integer
对于idx = Me.Panel1.Controls.Count - 1到0步-1
如果TypeOf Me.Panel1.Controls .Item(idx)是标签然后
Me.Panel1.Controls.RemoveAt(idx)
结束如果
下一页
我希望这会贡献一些东西
Cor
way minus. So I doubt if I will use it, but for the example I did use
"removeAT" (I think it is nicer). Please don''t start a discussion about
that. The question is the "While end while" against reversal "For next".

"While end While"
Dim idx As Integer
idx = 0
While idx < Me.Panel1.Controls.Count '' while in bounds
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
Else
idx = idx + 1 '' otherwise advance to next control
End If
End While
-----------------
"For index Next reversal"
Dim idx As Integer
For idx = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
End If
Next
I hope this contribute something
Cor




我2笔的时间。


我需要说的第一件事就是没有正确或错误的方式。什么

实现了你的目标并且适合你的发展风格适合

你。


那就说了一些做法在性能,资源使用等方面,其他方式往往比其他方式更好,但是,这些天有一些先进的

硬件规格,这里几毫秒在这里或那里,或者在这里或那里有几百万美元的纪念品可能不是你最关心的问题。


我倾向于工作的方式是使用电源尽可能的工具。


举个例子,问题可以证明:


Me.Panel1.Controls

Item 0 = Label1 As Label

Item 1 = Label2 As Label

Item 2 = Label3 As Label


首先发生的事情是你手动维护一个

索引计数器。与循环

控制变量相比,这可能是性能问题。

在循环的第一次迭代中,idx = 0,Me.Panel1.Controls .Count = 3和

TypeOf Me.Panel1.Controls.Item(idx)标签等于True(Label1),所以

删除第一个项目和集合现在包括:


Me.Panel1.Controls

项目0 = Label2作为标签

项目1 = Label3作为标签


在循环的第二次迭代中,idx = 0,Me.Panel1.Controls.Count = 2和

TypeOf Me.Panel1.Controls.Item(idx )Label是等于True(Label2),所以

第一项被删除,现在收藏包括:


Me.Panel1.Controls
项目0 = Label3作为标签


在循环的第三次迭代中,idx = 0,Me.Panel1.Controls.Count = 1和

TypeOf Me.Panel1.Controls.Item(idx)标签等于True(Label2),所以

第一个项目被删除而集合no w包括:


Me.Panel1.Controls


在循环的第四次迭代中,idx = 0,Me.Panel1.Controls。计数= 0,因此

不执行迭代。


请注意,idx尚未修改,因此手动维护的代码为

索引计数器是多余的。如果一个如果控件不是标签然后

idx将被修改但代码仍然必须执行idx = idx

+ 1.(这可以简化到idx + = 1)。


第二个例子,没有手动维护索引计数器 -

而是,索引由循环控制控制变量。因为

集合正在向后走,所以不需要idx = idx

+ 1,在我看来,这个过程更清洁,应该是效率更高。

它仍然可以简化:


idx为Integer = Me.Panel1.Controls.Count - 1 To 0 Step -1

如果TypeOf Me.Panel1.Controls.Item(idx)是标签那么

Me.Panel1.Controls.RemoveAt(idx)

下一页


对于那些如此倾向的人来说,比较这两种方法得到的IL代码并看看是否更高效,这可能会很有趣。 />
比另一个或者如果它们生成相同的IL代码。


请原谅任何拼写错误或琐碎的编码错误。


Cor < no*@non.com>在留言中写道

news:3f *********************** @ reader20.wxs.nl ...
Time for my 2 pen''orth.

The first thing I need to say is that there is no right or wrong way. What
ever achieves your objective and suits your development style is right for
you.

That said, some ways of doing things tend to be better that other ways in
terms of performance, resource usage etc, but, with some of the advanced
specification of hardware these days, a few milliseconds here and there or a
few KB of menory here or there may not be your biggest concern.

The way I tend to work is to to use the power of the tools as far as I can.

Taking your first example, the problem can be demonstrated thus:

Me.Panel1.Controls
Item 0 = Label1 As Label
Item 1 = Label2 As Label
Item 2 = Label3 As Label

The first thing that is happening is that you are manually maintaing an
index counter. This is a probably performance matter compared to a loop
control variable.

On the first iteration of the loop, idx=0, Me.Panel1.Controls.Count=3 and
TypeOf Me.Panel1.Controls.Item(idx) Is Label equates to True (Label1), so
the first item is removed and the collection now comprises:

Me.Panel1.Controls
Item 0 = Label2 As Label
Item 1 = Label3 As Label

On the second iteration of the loop, idx=0, Me.Panel1.Controls.Count=2 and
TypeOf Me.Panel1.Controls.Item(idx) Is Label equates to True (Label2), so
the first item is removed and the collection now comprises:

Me.Panel1.Controls
Item 0 = Label3 As Label

On the third iteration of the loop, idx=0, Me.Panel1.Controls.Count=1 and
TypeOf Me.Panel1.Controls.Item(idx) Is Label equates to True (Label2), so
the first item is removed and the collection now comprises:

Me.Panel1.Controls

On the forth iteration of the loop, idx=0, Me.Panel1.Controls.Count=0 and so
the iteration is not executed.

Notice that idx has not been modified so the code that manually maintains
the index counter is redundant. If one if the controls wasn''t a Label then
idx would have been modified but the code still had to execute the idx = idx
+ 1. (This could simplified to idx += 1).

Taking the second example, there is no manually maintained index counter -
instead, the indexing is controlled by the loop control variable. Because
the collection is being walked backwards there is no need for the idx = idx
+ 1 and, in my view the process is cleaner and ''should be'' more efficient.
It could still be simplified thus:

For idx as Integer = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls.Item(idx) Is Label Then
Me.Panel1.Controls.RemoveAt(idx)
Next

It might be interesting, for someone who is so inclined, to compare the
resulting IL code for the 2 methodologies and see if one is more efficient
than the other or if they produce the same IL code.

Please excuse any typos or trivial coding errors.

"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...

我从昨天(或今天早上为我们中的一些人)开始讨论讨论。这是一个关于从面板动态删除
控件的讨论还不是很好。
它是从我的一个例子开始的,这远远不是完整的并且有
输入错误,但基本上它有意义表明删除控件
可逆是最好的方法。

这是一个让我们说的结论(但在新闻组中是什么)在讨论中几个星期前在这个新闻组。该方法由Armin提供。我发现它很棒,从那时起我称之为方法
Armin。

杰克完全不同意这种方法,并在一段时间后做了
贡献了一些代码。

因此,我在这个新主题中将这两个代码发送到这个新闻组。我认为专业谈论这件事很好。所以这不是代码Cor,
Nick,Armin或Jack。只是方法反向下一个循环,对着While
end while loop,动态删除控件。

我不想从关于方法的点数开始,也许我会给b $ b,但是我希望它会自动出现这个新闻组

杰克为我做了一些贡献的代码,因为我没有知道removeAT。存在。但我总是按照
相同的方式做我做的事情。所以我怀疑我是否会使用它,但是我的确使用了
removeAT的例子。 (我认为它更好)。请不要开始讨论这个问题。问题是while while while反对逆转下一步。

虽然结束时
Dim idx为整数
idx = 0
而idx< Me.Panel1.Controls.Count''在界限内
如果TypeOf Me.Panel1.Controls.Item(idx)是标签然后
Me.Panel1.Controls.RemoveAt(idx)
Else
idx = idx + 1''否则前进到下一个控件
结束如果
结束时
-----------------
For index Next reversal
Dim idx As Integer
对于idx = Me.Panel1.Controls.Count - 1到0步-1
如果TypeOf Me.Panel1.Controls .Item(idx)是标签然后
Me.Panel1.Controls.RemoveAt(idx)
结束如果
下一页
我希望这会贡献一些东西
Cor



这篇关于关于删除动态控件的认真讨论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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