none
setting source for an image box RRS feed

  • Question

  • I have a window with an image boxes  named image1 through image5 in it.

    I have a directory containing 52 images of playing cards.

    The name of the directory is "Playing Cards".

    The file names in the directory are xx-resize,png. The -resize was added to the file names when I did a batch resize in my image editing software.

    I have built an array of 52 card names such as c2 for the deuce of clubs named CardDeck.

    I have another array called hands where I store five selected cards for four hands,

    The code to fill the CardDeck array and populate the hands array work as they should.

    I want to be able to a build a file name so I can set the Source property of the image box to the name of the file containing

    the the card image.

    I try to do  filename = "c:/Playing Cards/" + hands[0,3] + "-resize.png";

    or "c:\ etc.

    In either case I get errors saying "newline in constant" , "resize does not exist in this context".

    What is the proper code to build the filename or must I include the entire file name in the cardDeck array

    " + hands[0,4]" +


    John Scholl

    Monday, March 12, 2018 10:01 PM

Answers

  • Try one of these.

    filename = "c:\\Playing Cards\\" + hands[0,3] + "-resize.png";
    
    ...or...
    
    filename = @"c:\Playing Cards\" + hands[0,3] + "-resize.png";

    Backslash characters ('\') are used to place escape sequences into strings. If you want an actual backslash, you either double it or precede the string with an at character ('@').

    • Marked as answer by johnscholl Tuesday, March 13, 2018 4:26 AM
    Monday, March 12, 2018 10:34 PM

All replies

  • Try one of these.

    filename = "c:\\Playing Cards\\" + hands[0,3] + "-resize.png";
    
    ...or...
    
    filename = @"c:\Playing Cards\" + hands[0,3] + "-resize.png";

    Backslash characters ('\') are used to place escape sequences into strings. If you want an actual backslash, you either double it or precede the string with an at character ('@').

    • Marked as answer by johnscholl Tuesday, March 13, 2018 4:26 AM
    Monday, March 12, 2018 10:34 PM
  • Thanks again Ante. My card games is coming along. Almost to the most complex part - determining

    which of 4 hands is the winner.


    John Scholl

    Tuesday, March 13, 2018 4:29 AM