How to call a function when you don't know what function to call?
I'm making a small guessing game to learn more about methods. I want to use picture boxes for states and am utilizing a class that stores the state number, name, and name of the picture box. I have a random number between 1 & 50 that chooses the state. When that number is determined I want a foreach(iteration in state) to go through the state numbers and find the correct state to enable (make the picture of the state visible) with a pictureName.Visibible = true but this doesn't seem possible. Can anyone point me in a good direction on how to handle this?
19 Replies
pictureName is a string
?
which is incorrect but how can I turn that into the function itself
sounds like instead of
pictureName
being a string which is the name of some variable I'm assuming, instead that should store the reference to the picture objectright
thats correct
I don't know how to do that though
I'm not sure how to reference the picture object
What is the type of
picBox_Alabama
?I think i figured it out
give me a second
and here
I think its fixed
definately not
no its not showing the pictures
was really hopeful there
What am i doing wrong?
What if instead of a string property called pictureName in your State object, you had a property of type PictureBox that refers to the PictureBox control for that state?
Isn't that what I've done
here
and here
You made pictureName of type
object
it needs to be of type PictureBox
(probably)
I'm not a UI programmer
public PictureBox Picture { get; set; }
or something like thatI think that did it
That definitely fixed it
Thank you @mtreit !
Glad to help