Coding image change

it'll depend on how you want the images to be handled (imagelists or openfiledialog) but to change the form's image simply use the backgroundimage property but i think you're talking about the user's desktop background in which case i couldn't tell ya, but i do know a simple google search should lead you to the answer in a short amount of time :) maybe i'll do a quick search when i get the chance
 
Yeah I tryed to google it, but i'm a beginner and i'm just codeing for a 101 class I'm taking in school - So i didn't really understand most of the code but what I want to do is have the program run - then the user click a button - and for the background image to change.
 
In the click event of the button..

VB.NET:
Expand Collapse Copy
Me.BackgroundImage = image.fromfile(the file path to the image you want to display)

or if in an imagelist...

VB.NET:
Expand Collapse Copy
me.backgroundimage = imagelist.images(the index of the image you want to rtrieve)

or if an embedded resource...

VB.NET:
Expand Collapse Copy
dim Bmp as new bitmap = system.reflection.assembly.getexecutingassembly.
getmanifestresourcestream(filename)
 
me.backgroundimage = bmp
 
I tryed all the codes and I can't get it to work. What I want is to make a button on form1 -after the button is clicked- I want the form1 to take an certain image I have on the computer's harddrive to be displayed as the backround. Is that possible?

thank you

by the way, the image I want is a jpeg. if that matters.
 
sorry i havent been around the past few days here to continue helping

when dealing with strings you need to have the double quotes at the beginning and end of the string contents, so change this line:
VB.NET:
Expand Collapse Copy
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].BackgroundImage = Image.FromFile(C:\kosherdelight.jpeg)[/SIZE]

to:
VB.NET:
Expand Collapse Copy
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].BackgroundImage = Image.FromFile("C:\kosherdelight.jpeg")[/SIZE]


and of course if you want it to be more flexible you can use an OpenFileDialog to pick the location of the image and set it as the form's background:

VB.NET:
Expand Collapse Copy
Dim ofd As New OpenFileDialog
With ofd
  .Filter = "Jpeg (*.jpg)|*.jpg|GIF (*.gif)|*.gif"
  .FileName = "C:\"
  .Title = "Locate Image"
  If .ShowDialog() <> DialogResult.Cancel Then Me.BackgroundImage = Image.FromFile(.FileName)
End With
 
Is there a way to locally load the image into the form so a file path is not needed for loading the new background image??
 
a file path is always needed (this is true for all programming languages) but with VB if the full path is not specified, it'll look to the same folder as the executable (or dll) that's looking for it
 
Back
Top