Prev: The listview icon (16*16) color is no 32bit using ExtractIconwith imagelist
Next: create a bitmap from an intptr to scanned data
From: Massimo Riccardi on 20 Dec 2009 09:02 Hi all, I have an array of controls (made at runtime) and containing 10 buttons (Button(0),Button(1)....etc.). Ho I can get the index of a selected control? For example if I click the button number 5 how I can retrieve its index (that it is the fifth button)? (In VB6 there was the "INDEX" .....) Thanks Massimo
From: Family Tree Mike on 20 Dec 2009 11:01 On 12/20/2009 9:02 AM, Massimo Riccardi wrote: > Hi all, > > I have an array of controls (made at runtime) and containing 10 buttons > (Button(0),Button(1)....etc.). > Ho I can get the index of a selected control? > For example if I click the button number 5 how I can retrieve its index > (that it is the fifth button)? > (In VB6 there was the "INDEX" .....) > > Thanks > Massimo > > In your click handler: Dim b as Button = CType(sender, Button) dim idx as integer = Array.IndexOf(Button, b) -- Mike
From: eBob.com on 20 Dec 2009 11:11 Most straightforward would be to simply do a lookup. More efficient would be to take advantage of the Button's Tag property. I.E. simply set the Tag to the index value. Bob "Massimo Riccardi" <rimassimo(a)aliceposta.it> wrote in message news:4b2e2e6d$0$1106$4fafbaef(a)reader3.news.tin.it... > Hi all, > > I have an array of controls (made at runtime) and containing 10 buttons > (Button(0),Button(1)....etc.). > Ho I can get the index of a selected control? > For example if I click the button number 5 how I can retrieve its index > (that it is the fifth button)? > (In VB6 there was the "INDEX" .....) > > Thanks > Massimo >
From: Phill W. on 22 Dec 2009 06:09
Massimo Riccardi wrote: > I have an array of controls (made at runtime) and containing 10 buttons > (Button(0),Button(1)....etc.). > How I can get the index of a selected control? Why do you need it? Event handlers all receive a reference to the Control that raised the event, so you don't need to index for that ... Private Sub AnyButton_Click( _ byval sender as Object _ , byval e as EventArgs _ ) Dim btn as Button = Nothing If TypeOf sender is Button Then btn = DirectCast( sender, button ) End If btn.Text = ... End Sub HTH, Phill W. |