0

The user needs to fill in a form at the beginning of the game and I was trying to use their selected gender to generate which icon they will have. However I have tried many solutions to this problem and the picturebox either remains blank when I run the program, or only shows one of the pictures no matter which gender I pick. Does anyone know how I can fix this?

private void Form9_Load(object sender, EventArgs e)
{
    if (Form10.gender == "male")
    {
        pictureBox1.Image = Properties.Resources.playerboy;
    }
    else if (Form10.gender == "female")
    {
        pictureBox1.Image = Properties.Resources.playergirl;
    }
    else
    {
        pictureBox1.Image = Properties.Resources.playerother;
    }
}
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Buttons
  • 11
  • 3
  • 3
    It's generally not advised to use images for your code, it's better to paste your code into a code block. This is part of the guidelines for questions here on StackOverflow. – JoeTomks May 04 '18 at 08:48
  • 1
    You're changing the picture on the form load, since I'm guessing your user hasn't filled in the form yet, you'll need to pick the image after they've filled it in. – Sayse May 04 '18 at 08:50
  • 1
    I guess gender is not selected by user during form Load and will always have its initial value. Further more you check for Form10 property on Form9 load event – apomene May 04 '18 at 08:50
  • 1
    Tag wiki for [`visual-studio-2013`](https://stackoverflow.com/tags/visual-studio-2013/info) states: "Do not use this tag unless you have a specific question about Visual Studio -- not just a coding issue." -- I have now removed the tag for you. – ProgrammingLlama May 04 '18 at 08:53
  • Thank you for your help, I am new here so I did not know about the code block thing. In my program Form10 actually comes before Form9 because the user will fill in Form10 before accessing Form9. Is there a way I can post my actual program here so I can demonstrate this better? – Buttons May 04 '18 at 09:00
  • Do you actually have a valid refrence to the actual Form10, not just a reference to a new copy?? [See here](https://stackoverflow.com/questions/50159119/c-sharp-datagridview-doesnt-show-data-on-other-form?noredirect=1#comment87337957_50159119) – TaW May 04 '18 at 09:00
  • Do not post the whole program, just how form9 gets opened for starters.. Also show what the debugger tells you! – TaW May 04 '18 at 09:01
  • You should try to create an [mcve]. – Sayse May 04 '18 at 09:02

0 Answers0