I'm creating several pictureboxes in run time and want to know which has been clicked?
This is kind of a card game where is picturebox holds an image of a card and I want to know which card the user want to play(click).
Thanks.
Printable View
I'm creating several pictureboxes in run time and want to know which has been clicked?
This is kind of a card game where is picturebox holds an image of a card and I want to know which card the user want to play(click).
Thanks.
Are you using an array of pictureboxes?Quote:
Originally posted by Briansol
I'm creating several pictureboxes in run time and want to know which has been clicked?
This is kind of a card game where is picturebox holds an image of a card and I want to know which card the user want to play(click).
Thanks.
in the click event , the Sender parameter is the picturebox. You will have to convert it to a picturebox though:Quote:
Originally posted by Briansol
I'm creating several pictureboxes in run time and want to know which has been clicked?
This is kind of a card game where is picturebox holds an image of a card and I want to know which card the user want to play(click).
Thanks.
dim aPicBox as picturebox = directcast( sender, picturebox)
that would give you the clicked picturebox. Now to distinguish between them, you could either check the name of the picturebox, or you could use the .Tag property.
For example you could save the index of each picturebox when you are creating them in the Tag property of the picturebox. then when the user clicks on one of them, use Cint(aPicBox.Tag) to get the index. (That is, if you are using a control array for your pictureboxes)
Thanks,
I'm using an array for my pictureboxes, but how do I code the click event for the array? I can only get it working a variable with WithEvents.
oh hehe
use the AddHandler function, it's wonderful
dont have VS to test it, but I think something like this should work"
VB Code:
' hint hint use a smaller array size :rolleyes: dim pics(10000000000000) as picturebox sub foo for i= 0 to 10000000000000 pics(i) = new picturebox pics(i).tag = i 'save the index of the picturebox ' I hope this is the right syntax :). Basically it's registering the MouseClick event with the given sub addHandler pics(i).MouseClick, AddressOf pic_MouseClick next me.controls.addrange pics end sub private sub pic_MouseClick ( ??? , ??? ) ' Look up a picturebox's mouse click event and just use that. I dont know what the arguments are. Probably just a Sender As Object variable and a MouseEvents arg dim aPicBox as picturebox = directcast( sender, picturebox) dim index as integer = int.parse(apicbox.tag) ' that gives you the index, if it is of any use... you could just use aPicBox to access the picturebox, or pics(index), same thing. end sub
HTH
Got it working.
Thanks a lot ;)