lee croydon

lee croydon

  • NA
  • 48
  • 12k

Relative path to a image

Nov 12 2014 11:19 AM
Hi,
 
i am creating a poker game and have hit a brick wall, i am trying to bring the card images into the app for the players hand, flop, turn and river. i can do this using the absolute path as in the code below, but i need the app to be stand alone so that the images can be accessed for any machine it is download to (hence the relative path).
 
i am quite new to relative paths so please excuse my lack of knowledge, any help you offer or if you can point me in the right direction it would be greatly appreciated.
 
 
  Card card = new Card();
            List<Card> deckOfCards = new List<Card>();
            card.Deck(deckOfCards);

            List<Card> allCards = new List<Card>();

            var playersHand = deckOfCards.Take(2);
            int i = 0;
            string[] ph = new string[2];

            foreach (Card c in playersHand)
            {
                ph[i] = c.number.ToString() + c.suit.ToString() + ".png";
                i++;
                allCards.Add(c);
            }

            foreach (string image in ph)
            {
                imageList1.Images.Add(Image.FromFile(@"C:\Users\DELL User\Dropbox\Computeach\LeeCroydon.PokerGame.Table\LeeCroydon.PokerGame.Table\MyCards\" + image));
            }
            playerOneCard1.Image = imageList1.Images[0];
            playerOneCard2.Image = imageList1.Images[1];
            playerOneCard1.Show();
            playerOneCard2.Show();
            
 
            deckOfCards.RemoveRange(0, 2);
            

            var burnCard = deckOfCards.Take(1);

            foreach (Card c in burnCard)
            {
                deckOfCards.Remove(c);
            }

            var flop = deckOfCards.Take(3);
            string[] fp = new string[3];
            i = 0;
            foreach (Card c in flop)
            {
                fp[i] = c.number.ToString() + c.suit.ToString() + ".png";
                i++;
                allCards.Add(c);
            }
            
            foreach (string image in fp)
            {
                imageList1.Images.Add(Image.FromFile(@"C:\Users\DELL User\Dropbox\Computeach\LeeCroydon.PokerGame.Table\LeeCroydon.PokerGame.Table\MyCards\" + image)); 
            }
            flop1.Image = imageList1.Images[2];
            flop2.Image = imageList1.Images[3];
            flop3.Image = imageList1.Images[4];
            flop1.Show();
            flop2.Show();
            flop3.Show();

            deckOfCards.RemoveRange(0, 3);
            

            burnCard = deckOfCards.Take(1);

            foreach (Card c in burnCard)
            {
                c.isUsed = true;
            }

            var turn = deckOfCards.Take(1);
            string[] tn = new string[1];
            i = 0;
            foreach (Card c in turn)
            {
                tn[i] = c.number.ToString() + c.suit.ToString() + ".png";
                deckOfCards.Remove(c);
                allCards.Add(c);
            }
            foreach (string image in tn)
            {
                imageList1.Images.Add(Image.FromFile(@"C:\Users\DELL User\Dropbox\Computeach\LeeCroydon.PokerGame.Table\LeeCroydon.PokerGame.Table\MyCards\" + image));
            }
            turnCard.Image = imageList1.Images[5];
            turnCard.Show();

            burnCard = deckOfCards.Take(1);
            card.isUsed = deckOfCards.Contains(card);

            foreach (Card c in burnCard)
            {
                deckOfCards.Remove(c);
            }

            var river = deckOfCards.Take(1);
            string[] rir = new string[1];
            i = 0;
            foreach (Card c in river)
            {
                rir[i] = c.number.ToString() + c.suit.ToString() + ".png";
                deckOfCards.Remove(c);
                allCards.Add(c);
            }
            foreach (string image in rir)
            {
                imageList1.Images.Add(Image.FromFile(@"C:\Users\DELL User\Dropbox\Computeach\LeeCroydon.PokerGame.Table\LeeCroydon.PokerGame.Table\MyCards\" + image));
            }
            riverCard.Image = imageList1.Images[6];
            riverCard.Show();
 
thank you in advance Lee :) 

Answers (3)