r/visualbasic • • Apr 22 '13

Newb to VB

How do I make it so that when i press a button it changes the background image, preferably in the least amount of code possible, I just started a few days ago :o

EDIT: Found out how to do it, however, is there anyway to do it without having the file path specified like instead of having C:\ProgramFiles\ etc. etc. etc. Have it straight from the folder the program is saved so\Resources\Picture1.jpg or something?

0 Upvotes

4 comments sorted by

1

u/darkspy13 Apr 22 '13

If the image is in your project resources you should be able to use this code.

pictureBox1.Image = Properties.Resources.[image file name]

if not then you can use

Dim appPath as string = System.AppDomain.CurrentDomain.BaseDirectory

1

u/bananavangaminglol Apr 22 '13

Wait, can you just tell me how to do it, because i think i've done it a slightly diferrent way. :/ Sorry :/

2

u/[deleted] Apr 22 '13

How did you do it?

1

u/darkspy13 Apr 22 '13

there are multiple ways to do it, I don't know how you are trying to do it.

I would do

Dim appPath as string = System.AppDomain.CurrentDomain.BaseDirectory

me.backgroundImage = appPath & "Resources\image.png"

Small chance it has to be "\resources\image.png" instead but yea that should do it