button array

  • Thread starter Thread starter Tombatore
  • Start date Start date
T

Tombatore

hello people,

I've created an array of buttons by code to have an array :
buttons(size, size)
I am programming a version of mine sweeper, and one button is a
clickable rectangle with an image on each of them.

For each of these buttons I do the following after their declaration:
AddHandler buttons(row, col).MouseUp, AddressOf buttonclick

My question is, how do I know in my eventhandler which button was
pressed?

Thanks in advance!

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
Tombatore

Assuming you have used the text to set in the row and the tag for the col.
(text is string, tag is object). Just typed in here so watch typos

\\\
MyhandledButtonCol = Cint(directcast(sender,button).text)
MyhandledButtonRow = Cint(directcast(sender, button).tag)
///

Just an idea I hope this helps?

Cor
 
Tombatore said:
I've created an array of buttons by code to have an array :
buttons(size, size)
I am programming a version of mine sweeper, and one button is a
clickable rectangle with an image on each of them.

For each of these buttons I do the following after their declaration:
AddHandler buttons(row, col).MouseUp, AddressOf buttonclick

My question is, how do I know in my eventhandler which button was
pressed?

Set the button's name to a unique ID and then use...

\\\
Dim SourceControl As Button = DirectCast(sender, Button)
Select Case SourceControl.Name
Case...
...
...
End Select
///
 
Tombatore said:
I've created an array of buttons by code to have an array :
buttons(size, size)
I am programming a version of mine sweeper, and one button is a
clickable rectangle with an image on each of them.

For each of these buttons I do the following after their declaration:
AddHandler buttons(row, col).MouseUp, AddressOf buttonclick

My question is, how do I know in my eventhandler which button was
pressed?


I would suggest you don't use an array of buttons becuase it is overkill
for what you want to do. You will have far too many buttons for the
form. Instead, do your own drawing to make a panel appear as an
array of buttons, and simply calculate from the mouse X and Y positions,
which button got hit.

For an example of drawing a button, check out this link:
http://groups.google.com/groups?hl=en&lr=&safe=off&[email protected]

LFS
 
Back
Top