C
C#2y ago
Grin

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
Grin
Grin2y ago
mtreit
mtreit2y ago
pictureName is a string ?
Grin
Grin2y ago
which is incorrect but how can I turn that into the function itself
Saber
Saber2y ago
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 object
Grin
Grin2y ago
right thats correct I don't know how to do that though
Grin
Grin2y ago
Grin
Grin2y ago
I'm not sure how to reference the picture object
mtreit
mtreit2y ago
What is the type of picBox_Alabama ?
Grin
Grin2y ago
I think i figured it out give me a second
Grin
Grin2y ago
Grin
Grin2y ago
and here
Grin
Grin2y ago
I think its fixed
Saber
Saber2y ago
definately not
Grin
Grin2y ago
no its not showing the pictures was really hopeful there What am i doing wrong?
mtreit
mtreit2y ago
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?
Grin
Grin2y ago
Isn't that what I've done here and here
mtreit
mtreit2y ago
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 that
Grin
Grin2y ago
I think that did it That definitely fixed it Thank you @mtreit !
mtreit
mtreit2y ago
Glad to help