7 Replies - 3188 Views - Last Post: 27 March 2013 - 02:51 PM Rate Topic: -----

#1 jsheehan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 14-February 13

how to fill a picture box with a deck of cards?

Posted 27 March 2013 - 10:58 AM

i am working on a blackjack game in vb 2010. I want to have 3 random cards from the deck of 52 in each of the 2 picture boxes i have created. I have used a Select Case for the cards, and i can get the 1st card to appear. The code i have so far i
picturebox1.image = image.fromfile("C:\Users\Winvista\Documents\cards\1.png



How can i populate each picture box with all 52 cards in one go, or would i have to declare each one seprately?

Is This A Good Question/Topic? 0
  • +

Replies To: how to fill a picture box with a deck of cards?

#2 andrewsw   User is online

  • head thrashing
  • member icon

Reputation: 6627
  • View blog
  • Posts: 27,096
  • Joined: 12-December 12

Re: how to fill a picture box with a deck of cards?

Posted 27 March 2013 - 12:14 PM

One (incomplete) line of code is not particularly helpful.

However, the PictureBox is intended to display a single image. It is possible to use a Graphics object to create an image (from other images) and then use this, but simpler would be to use a Panel control and just insert the number of PictureBoxes that you need (that is, one for each image) into this panel.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is online

  • head thrashing
  • member icon

Reputation: 6627
  • View blog
  • Posts: 27,096
  • Joined: 12-December 12

Re: how to fill a picture box with a deck of cards?

Posted 27 March 2013 - 12:21 PM

There is some interesting code here at SO to combine several images to one. It is in C# but not too difficult to translate.

However, as I mentioned, using a Panel with a number of PictureBoxes is much easier.

This post has been edited by andrewsw: 27 March 2013 - 12:22 PM

Was This Post Helpful? 0
  • +
  • -

#4 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1515
  • View blog
  • Posts: 3,832
  • Joined: 01-February 13

Re: how to fill a picture box with a deck of cards?

Posted 27 March 2013 - 01:11 PM

Hello,
I would fill a List(Of String) or a String Array with the path of each card randomly. Then just create the first 6 pictureboxes at first. 2 for the player, 2 for the dealer, and 1 for the card deck and remove the cards from the list as they are dealt. As the player or dealer takes a new card create a new picturebox for them at that time and remove that card from the list. Keep going until someone wins or the cards need to be shuffled again. At that point you could get rid of all the pictureboxes not needed and start creating new ones again. Chances are you would not need 52 pictureboxes at any given time for the game. However that`s just my opinion. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#5 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: how to fill a picture box with a deck of cards?

Posted 27 March 2013 - 01:31 PM

Can anyone say control heavy? You can simply use Rectangles and draw to there coordinates using GDI+. A good design would use classes for the cards and the main form with have a deck class that held the cards, then have a mechanism for drawing an where in the rectangle layout you design for the surface.
Was This Post Helpful? 1
  • +
  • -

#6 andrewsw   User is online

  • head thrashing
  • member icon

Reputation: 6627
  • View blog
  • Posts: 27,096
  • Joined: 12-December 12

Re: how to fill a picture box with a deck of cards?

Posted 27 March 2013 - 01:50 PM

View Post_HAWK_, on 27 March 2013 - 08:31 PM, said:

Can anyone say control heavy? You can simply use Rectangles and draw to there coordinates using GDI+. A good design would use classes for the cards and the main form with have a deck class that held the cards, then have a mechanism for drawing an where in the rectangle layout you design for the surface.

I was assuming the OP might only be displaying 3 cards (images) at any one time - didn't delve beyond the initial request :)
Was This Post Helpful? 0
  • +
  • -

#7 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: how to fill a picture box with a deck of cards?

Posted 27 March 2013 - 02:41 PM

Don't think I was picking on anyone. After using a design similar, not cards though, with picturebox as my canvas and was able to draw the class objects where ever and how ever based on the class definitions - it just felt like it was wired nicely. Change something in the class objects and your drawing simple reflected that. AdamSpeight has a great tut on that as well.
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw   User is online

  • head thrashing
  • member icon

Reputation: 6627
  • View blog
  • Posts: 27,096
  • Joined: 12-December 12

Re: how to fill a picture box with a deck of cards?

Posted 27 March 2013 - 02:51 PM

View Post_HAWK_, on 27 March 2013 - 09:41 PM, said:

Don't think I was picking on anyone. After using a design similar, not cards though, with picturebox as my canvas and was able to draw the class objects where ever and how ever based on the class definitions - it just felt like it was wired nicely. Change something in the class objects and your drawing simple reflected that. AdamSpeight has a great tut on that as well.

It also depends on which version of black jack the OP is designing :whatsthat:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1