winforms buttons in an array ?

  • Thread starter Thread starter n3crius
  • Start date Start date
N

n3crius

guys, is it possible to make an array of buttons for my form so i can
iterate through them and initalise a lot of them easily, ive actually
never seen this done and have only just realised, and so, i'm actually
quite scared!

--
One framework to rule them all...

@@@ @@@ @@@@@@ @@@@@@@ @@@@@@@ @@@ @@@ @@@ @@@@@@
@@!@!@@@ @@! !@@ @@! @@@ @@! @@! @@@ !@@
@!@@!!@! @!!!: !@! @!@!!@! !!@ @!@ !@! !@@!!
!!: !!! !!: :!! !!: :!! !!: !!: !!! !:!
:: : ::: :: :: :: : : : : : :.:: : ::.: :

n3crius > .net programmer (c#/asp.net)
 
All buttons on a form are already contained in a collection in their
container (either the form, or a panel or groupbox on the form). So you can
iterate through them like this:


Dim opt As New Control
For Each opt In grpType.Controls
If CType(opt, RadioButton).Checked Then
'DoSomething
End If
Next


http://www.knowdotnet.com/articles/thedotnetway.html

Is this essentially what you want to do?
 
Also, (I thought I included this in my last post but I guess not), you can
attach multiple event handlers to a function. So, the code you used to
handle Button1.Click can handle button2, 3, 4, etc , just by adding a
handler for each one. While I 'm not sure this is what you were looking for
in your post, this is the best way to simulate a 'control array' from VB6.

HTH,

Bill
 
Back
Top