Iterating through images in resources

09-07-2006, 06:06 AM
Hi all. Still getting to grips with .NET, and having a lot of fun creating my own control arrays with code. Let me explain what I'm doing

I want to create a small array of playing cards that the user can click on.

I have created a base-class called BaseSmallCard, which inherits from forms.picturebox.


Public Class BaseSmallCard
Inherits Windows.Forms.PictureBox

Public Sub New()

'Size of the picturebox
Me.Width = 28
Me.Height = 34

End Sub

Protected Overrides Sub Finalize()
End Sub
End Class

I then instantiate the array of basecards in the code below for the user interface.


Private Sub AddCardInterface()

'We need to create an interface for hearts,clubs,diamonds and spades interfaces seperately, with an
'index for the value, which can be evalue and an index for suit (esuit)

'Create dimensions for the loop
Dim CardLoop As eValue
Dim SuitLoop As eSuit

'Create the name for the hearts picture boxes
Dim CardPicture(eValue.King, eSuit.Spades) As BaseSmallCard

'Start the loop to create the cards
For CardLoop = eValue.Ace To eValue.King
For SuitLoop = eSuit.Hearts To eSuit.Spades
'Instantiate the new small card picture box
CardPicture(CardLoop, SuitLoop) = New BaseSmallCard
'Set the location of the small card
CardPicture(CardLoop, SuitLoop).Parent = formTableInterface.PanelUserInterface
'Determine where each card should be located
'Picture boxes are 34 high, so top will be suit value * 34
CardPicture(CardLoop, SuitLoop).Top = (SuitLoop * 34)
'Determine left property of the picturebox
'Picture boxes are 28 wide, so left will be its (index value * 28) - 28
CardPicture(CardLoop, SuitLoop).Left = (CardLoop * 28) - 28
CardPicture(CardLoop, SuitLoop).Image = My.Resources.c01
'Set the stretch picture value to true
CardPicture(CardLoop, SuitLoop).SizeMode = PictureBoxSizeMode.StretchImage
CardPicture(CardLoop, SuitLoop).Show()

End Sub

At the moment, as you can see in the code above, all card pictureboxes have the same image. (FYI, Ace of Clubs). I have added all the card GIF's to the Resources folder. I want to know if there is any way I can iterate through the list of images to set each card to its corresponding value.
I have named the images in the resources folder in the format
c01 - ace of clubs
c09 - nine of clubs
d13 - king of diamonds etc, etc

If there was some way I could create a path string to get to the resources folder this would be great, or is there another approach I could/should try?

Any input is much appreciated!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum