Nathan
Nathan

Reputation: 1250

Display image that depends on user input

I'm planning on creating a program that will have a login form and then a profile for each user. I'll be putting a picturebox that will display the image of the user.

My problem is how to put a variable in the Image.FromFile(); parameter.

The image will come from a local folder, btw.

Here's what I would like to do:

  1. user logs in (ie. user name is stackoverflow)
  2. on the profile window, an image named stackoverflow.jpg should be displayed.

Is there a way I can do that?

Image.FromFile("c:\filename.jpg"); <--- change the parameter with a variable that will depend on the username of the user.

Upvotes: 0

Views: 748

Answers (1)

jzworkman
jzworkman

Reputation: 2703

Why not just have each file saved as the username:

Image.FromFile(imageDirectory + username + ".jpg");

would then return the file associated with that user. imageDiretory can be set as a variable so you dont have to change it everywhere in the code if the directory changes where you store the files, and then the username can be determined when the user logs in.

Upvotes: 3

Related Questions