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