Picture Box & Button

lord.ec

New member
Joined
Dec 2, 2006
Messages
3
Programming Experience
Beginner
Can anyone tel me how can i
code the button so that when i click on it then
it shows an image and
when i click on another button(button2) it shud show another image..


Please help me out.
Im a noob in VB.net..
 
Please post in the most appropriate forum. Moved.

Handle each Button's Click event. To create a Click event handler for a Button you double-click it in the designer. In each event handler you need to assign your Image to the PictureBox. There are a number of ways to do that and the best depends on your situation. If you're using images contained in files on disc then the most likely method is to call the PictureBox's Load method and pass it the path to the image file.
 
Check this code--Picturebox and Button

Please post in the most appropriate forum. Moved.

Handle each Button's Click event. To create a Click event handler for a Button you double-click it in the designer. In each event handler you need to assign your Image to the PictureBox. There are a number of ways to do that and the best depends on your situation. If you're using images contained in files on disc then the most likely method is to call the PictureBox's Load method and pass it the path to the image file.

Suppose if i want to include all the images in the package(project) itself then what shud be the code for it.

I tried this code on the button event (i wrote the code by double clicking the button)

VB.NET:
picturebox1.image="1.jpg"

where 1.jpg was the image that i imported in the project.But it showed me the error..
please tell me wt shud i do.
I dont want my images in the external media like CDS..
please help me out..
 
try: PictureBox1.Image = Image.FromFile("1.jpg") if it's in the same dir as the exe file

or you could use an ImageList so it would be PictureBox1.Image = ImageList1.Images(0)

or you could access it as a resource using the 'My' keyword but i dont know exactly how that works (I just installed VS2005 pro a day ago and have yet to seriously get into it)
 
Go to the Resources tab of the project properties and add your image files there as resources. Give them more descriptive names than "1". You can then load them at run time from the My.Resources namespace. For instance, if you add an image resource named Image1, you would display it in a PictureBox like so:
VB.NET:
Me.PictureBox1.Image = My.Resources.Image1
 
@JuggaloBrotha
Thanks mate.But the thing is that
imagelist method doesnot show Gif images.It show them but they do not move..Can u pls tell me any reason and alternative for that ??

@jmcilhinney
I love you my friend.This method worked but i dnt kno why the speed of Gif image is reduced..
can u explain that
 
This method worked but i dnt kno why the speed of Gif image is reduced..
can u explain that
I'm going to guess and say that the frames of the GIF are retrieved from the resources as needed, causing a delay between frames. If this is the case then I would think that once all frames had been shown once that the animation should resume normal speed. If this is the issue then it might be overcome by creating an Image object from the resource first, then putting that Image in the PictureBox. As I said, this is just a guess.
 
Back
Top