Loop thru WinForm Controls

A

Armin Zingler

Am 10.04.2010 17:53, schrieb johnb:
Hi All
What is the code to loop thru all textbox controls on a form?

Inside the Form itself only or also inside other containers on the Form?
The former (it's shorter ;-) ):

'assuming option infer on
for each c in controls
if typeof c is textbox then
with directcast(c, textbox)
.property = value
end with
end if
next
 
P

PvdG42

C

Cor Ligthert[MVP]

Peter,

I've seen that the getType is currently more popular, but why not the way we
here in this newsgroup has done it forever.

If Typeof object Is Classname?

http://www.vb-tips.com/ControlBorder.aspx

Is this a kind of verCSharping (I don't know if you knows a tiny little bit
Dutch, then you understand it)

It means something as: using C# ways, where there is a very good VB
alternative.

:)

Cor
 
P

PvdG42

Cor Ligthert said:
Peter,

I've seen that the getType is currently more popular, but why not the way
we here in this newsgroup has done it forever.

If Typeof object Is Classname?

http://www.vb-tips.com/ControlBorder.aspx

Is this a kind of verCSharping (I don't know if you knows a tiny little
bit Dutch, then you understand it)

It means something as: using C# ways, where there is a very good VB
alternative.

:)

Cor
I'm not trying to start anything, just trying to offer the OP a way the
"learn to fish".
Your way is certainly just as good, and certainly more VB-traditional.
 
J

johnb

Hi Guys

Thank you for your useful comments. Yeah I'm learning to fish with this one
but good have more than one rod in the bag.

Thanks once more

johnb
 
A

Armin Zingler

Am 11.04.2010 03:39, schrieb PvdG42:
I'm not trying to start anything,

But you did. :)
just trying to offer the OP a way the
"learn to fish".
Your way is certainly just as good,

I'm not a native English speaker, so what does "*just* as good" mean
in _this_ case? :) "ok, use it if you want", or "as good as", or
"better than"?

I say TypeOf is to be preferred because it's "just quicker".
About 3.5x quicker (in my personal, I predict that one will say
disputable, tests). (yes, and I do know that both methods are not the same
because TypeOf includes inherited classes). And, BTW, TypeOf is 1:1
translated to the "isinst" IL keyword.
and certainly more VB-traditional.

Curly braces in C are also traditional. AND THAT DAMNED
CASE SENSITIVITY TOOOOO! Ummm... sorry, Sunday morning... ;)
 
P

PvdG42

Armin Zingler said:
Am 11.04.2010 03:39, schrieb PvdG42:

But you did. :)


I'm not a native English speaker, so what does "*just* as good" mean
in _this_ case? :) "ok, use it if you want", or "as good as", or
"better than"?

I say TypeOf is to be preferred because it's "just quicker".
About 3.5x quicker (in my personal, I predict that one will say
disputable, tests). (yes, and I do know that both methods are not the same
because TypeOf includes inherited classes). And, BTW, TypeOf is 1:1
translated to the "isinst" IL keyword.


Curly braces in C are also traditional. AND THAT DAMNED
CASE SENSITIVITY TOOOOO! Ummm... sorry, Sunday morning... ;)

Then, I should have said "you way is better". I stand corrected.
Thanks, Armin. I was not aware of the significant performance difference.
 
P

PvdG42

johnb said:
Hi Guys

Thank you for your useful comments. Yeah I'm learning to fish with this
one
but good have more than one rod in the bag.

Thanks once more

johnb
Pay close attention to Armin's latest post. Note the significant improvement
difference using TypeOf.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top