button array

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
*-----------------------*
 
C

Cor Ligthert

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
 
H

Herfried K. Wagner [MVP]

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
///
 
L

Larry Serflaten

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
 

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

Top