Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eventhandler for arraylist

Status
Not open for further replies.

SMURF75

Programmer
Aug 28, 2004
87
GB
Hi!

Im trying to create a little cardgame for my mom :),
and sending cards back and forth has my code look like a whole pot of spagetthi... so if anyone please know of a way to to link my picturebox.image to to the first object in my arraylist let me know about it.

An eventhandler for arraylist... or does anyone have a better idea?
 
Hi Smurf75,

You have not mentioned what is the structure of your arraylist. I assume that it contains a list of texts that point to a number of .jpg files for the images.

Public T As ArrayList = New ArrayList()
t.add("spade_ace.jpg")
....

Dim img as Image
Dim i as Integer
For i = 0 To T.Count
img=Image.FromFile(t.item(i))
pictureBox1.Image = img
...
Next

If I have not answered you question, please supply your code that indicate how you generated the ArrayList, how you intend to use the ArrayList, and what is the problem involved.

Happy Programming.
 
Hi... sorry to say, but that wasnt the answer i was looking for ;)
But with bad expressed questions i have ony myself to blame.

Ok... so for the arraylist i have a clsCard that i add which looks something like this.
Code:
Public class clsCard

dim intRank as integer
dim intSuit as String
dim imgCardPicture

' and the functions to give them values.

End Class

I create a deck with 104 cards that i then supply to 13 different arraylist
Code:
arrCurrentCardHand.add(clsCard)
When the solitaire begins the cards will be moved back and forth in a lot of arrayboxes. My problem is that i have enough of codelines just by moving those cards around, and making the equal amount of code just to keep the pictureboxes uppdated with the card that is on top of a certain arraylist feels like a waste.

So the solution im looking for is a sub that checks if an arraylist have had a change of count. This example dont work, but maybe you get what im after.
Code:
Public sub onArrayCountChange(sender as System.Object)_
handles arrCurrentHand.Change,moreArrs.Changes,evenMoreArrs.Change

somepicturebox.image = sender.Item(sender.count -1)

End sub
...hope this helps you to help me.

PS. An alternative can be if i could control the arrylist from the picturbox? Can that be done?


 
a little correction of my last post

Code:
Public class clsCard

dim intRank as integer
dim strSuit as String
dim imgCardPicture as Image

' and the functions to give them values.

End Class

Ot: Isnt there anyway to edit posts here?



Excuse me for my English. Excuse me that im slow. Excuse me that i dont understand.
Excuse me for my signature but now i dont have to write this in every single post :D
 
I believe I understand your problem better this time.

You mentioned above difficulty of organizing main code (pot of spaghetti). As a possible approach to organize code, I suggest using an array of 13 stacks. This way, much of your code will be reusable.

The class may be called clsStack, with an arraylist as one of the members. The array of clsStack instances may be declared at the module level so it will accessible everywhere.

Along those lines, you could update any modified stack(i) simply by calling Display(i):

' class definition
Public class clsStack
dim arrImgArray as ArrayList
'... Add subs to edit arraylist
End Class

' module level stack instances
dim Stacks(13) as clsStack = new clsStacks()

' sub to display/update top card of stack
Public Sub Display(i)
somepicturebox.image = Stacks(i).Item(Stacks(i).arrImgArray.count -1)
End Sub


Happy programming.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top