VS 2005 How to make picturebox from one form change by another form? (please help!)-VBForums
Results 1 to 3 of 3

Thread: How to make picturebox from one form change by another form? (please help!)

  1. #1

    Thread Starter
    New Member Zxriou's Avatar
    Join Date
    Nov 2017
    Location
    Lithuania
    Posts
    5

    Question How to make picturebox from one form change by another form? (please help!)

    Hello Coders.
    I am making a race game, and i have made it so when launched, it opens up a "launcher", where it lets you choose a car of choice before clicking start (which opens up another form, the game itself.)
    What i want to do, is so that if lets say, the picturebox in the launcher was a peugeot 206, and then click start, the picture box in the other form (the game) will be the peugeot.
    How do i do that?
    Here is a concept code so you will understand what i am trying do :
    ---------------
    If My.Forms.GameLauncher.PictureBox = My.Resources.Peugeot206 then
    PictureBox.Image = Peugeot206Racing
    ---------------
    Help a coder newbie out?
    Thanks!

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,587

    Re: How to make picturebox from one form change by another form? (please help!)

    Welcome to VBForums

    The simplest solution is to copy the image across, eg:
    Code:
    PictureBox.Image = My.Forms.GameLauncher.PictureBox.Image
    However, if that isn't appropriate for any reason: The idea you used is a good way to go, unfortunately you can't compare pictures that easily... even if GameLauncher.PictureBox was set to use the image from My.Resources.Peugeot206, they will not actually be the same image (just two images that happen to contain the same pixels), so won't be treated as equal.

    What you can do is use the Tag property of the PictureBox (the Tag property of controls is for you to store any data you like, and is not used by the control itself) to store some kind of text to identify the picture, and then read it when you want to check what the image is, eg:
    Code:
    'Setting the original Image and Tag:
    My.Forms.GameLauncher.PictureBox.Image = My.Resources.Peugeot206
    My.Forms.GameLauncher.PictureBox.Tag = "Peugeot206"
    Code:
    'Checking the Tag:
    If My.Forms.GameLauncher.PictureBox.Tag.ToString = "Peugeot206" then
        PictureBox.Image = Peugeot206Racing

  3. #3

    Thread Starter
    New Member Zxriou's Avatar
    Join Date
    Nov 2017
    Location
    Lithuania
    Posts
    5

    Talking Re: How to make picturebox from one form change by another form? (please help!)

    Wow, thanks a lot!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width