I'm a total noobie with VB6, I just started learning a few days ago from tutorials online.
Anyway, my question is, how can I use one picture box to load and display up to 48 .gif's or .bmp's? I want to be able to use Next and Back buttons to browse through them by clicking. I made an image list and added all the images to my resources already...and though I can't seem to find any more information about this, I'm pretty sure there's no way I'd have to make 48 pictures boxes/96 buttons and make 1 visible = true while the rest false, that just seems too redundant!
I apologize if this is actually a really stupid question or something =[ I've refrained from asking on a forum right away and already wasted more than two days trying to figure it out from google or just on my own.
I asked on Yahoo! Answers as well, and someone mentioned something about counters...but again, I'm a total beginner to VB =[ and he didn't leave anything specific or definitive, so I apologize if this is troublesome. Thank you very much for your time!
Help: Multiple Image, Single Picture Box......with "Next" & "Back" buttons...
Page 1 of 1
7 Replies - 10524 Views - Last Post: 29 May 2012 - 09:23 AM
Replies To: Help: Multiple Image, Single Picture Box...
#2
Re: Help: Multiple Image, Single Picture Box...
Posted 21 July 2008 - 02:52 PM
Rannison, on 21 Jul, 2008 - 10:36 PM, said:
I'm a total noobie with VB6, I just started learning a few days ago from tutorials online.
Anyway, my question is, how can I use one picture box to load and display up to 48 .gif's or .bmp's? I want to be able to use Next and Back buttons to browse through them by clicking. I made an image list and added all the images to my resources already...and though I can't seem to find any more information about this, I'm pretty sure there's no way I'd have to make 48 pictures boxes/96 buttons and make 1 visible = true while the rest false, that just seems too redundant!
I apologize if this is actually a really stupid question or something =[ I've refrained from asking on a forum right away and already wasted more than two days trying to figure it out from google or just on my own.
I asked on Yahoo! Answers as well, and someone mentioned something about counters...but again, I'm a total beginner to VB =[ and he didn't leave anything specific or definitive, so I apologize if this is troublesome. Thank you very much for your time!
Anyway, my question is, how can I use one picture box to load and display up to 48 .gif's or .bmp's? I want to be able to use Next and Back buttons to browse through them by clicking. I made an image list and added all the images to my resources already...and though I can't seem to find any more information about this, I'm pretty sure there's no way I'd have to make 48 pictures boxes/96 buttons and make 1 visible = true while the rest false, that just seems too redundant!
I apologize if this is actually a really stupid question or something =[ I've refrained from asking on a forum right away and already wasted more than two days trying to figure it out from google or just on my own.
I asked on Yahoo! Answers as well, and someone mentioned something about counters...but again, I'm a total beginner to VB =[ and he didn't leave anything specific or definitive, so I apologize if this is troublesome. Thank you very much for your time!
Are you use vb6 or one of the express versions of VB.net?
This post has been edited by AdamSpeight2008: 21 July 2008 - 02:52 PM
#3
Re: Help: Multiple Image, Single Picture Box...
Posted 21 July 2008 - 07:36 PM
Since you've specified that this was VB 6, I'm going to give you an answer in that language, though after what Adam said it makes me wonder if I missed something in your post pointing to .NET. From what I've seen though, when people post here when it's a .NET question, they don't even know what "6" or ".NET" is, meaning they don't know there's different versions and that they're significant, which is what led them to post in the wrong section in the first place.
This is very possible, so don't worry.
Make sure you know the name of every image in the folder. You might want to look into the process of listing the contents of a directory (to find out the names of all the images), which isn't too hard, though if the files will be changing you will HAVE to do this since this will be the only way of knowing the names of the files.
If the images are named in sequence like "Image1", "Image2", "Image3", then you could simply use a counter and construct the path of the image before each loading into the picturebox.
Now, to load a picture into a picturebox you can use the LoadPicture() function. All you gotta do is go through a list of the images (their file paths), and whichever particular image you're on you load using that nifty function.
How do you want to handle the image's dimensions? Do you want every image to be stretched/shrunk to fit into the picturebox's dimensions, or do you want to make the picturebox resize for every image? Or a combination of both?
Maybe all the images are the same size, I don't know.
To have the picturebox resize to the dimensions of the image, use its AutoSize property.
To have the images be shrunk/stretched to fit the picturebox, load them first into an invisible picturebox with AutoSize set to true, and then use the PaintPicture() function or StretchBlt API to stretch them to the size of your picturebox.
This is very possible, so don't worry.
Make sure you know the name of every image in the folder. You might want to look into the process of listing the contents of a directory (to find out the names of all the images), which isn't too hard, though if the files will be changing you will HAVE to do this since this will be the only way of knowing the names of the files.
If the images are named in sequence like "Image1", "Image2", "Image3", then you could simply use a counter and construct the path of the image before each loading into the picturebox.
Now, to load a picture into a picturebox you can use the LoadPicture() function. All you gotta do is go through a list of the images (their file paths), and whichever particular image you're on you load using that nifty function.
LoadPicture("C:\Lala.bmp")
How do you want to handle the image's dimensions? Do you want every image to be stretched/shrunk to fit into the picturebox's dimensions, or do you want to make the picturebox resize for every image? Or a combination of both?
Maybe all the images are the same size, I don't know.
To have the picturebox resize to the dimensions of the image, use its AutoSize property.
To have the images be shrunk/stretched to fit the picturebox, load them first into an invisible picturebox with AutoSize set to true, and then use the PaintPicture() function or StretchBlt API to stretch them to the size of your picturebox.
This post has been edited by Zhalix: 21 July 2008 - 07:40 PM
#4
Re: Help: Multiple Image, Single Picture Box...
Posted 21 July 2008 - 07:48 PM
Just to qualify what made me ask the question?
Rannison stated they had made an image list.
An imagelist is a toolbox item in VB.Net and can be add to a form, it used to store images in.
or
Have they made a list of images. (Could be an Array)
Rannison stated they had made an image list.
An imagelist is a toolbox item in VB.Net and can be add to a form, it used to store images in.
or
Have they made a list of images. (Could be an Array)
This post has been edited by AdamSpeight2008: 21 July 2008 - 09:15 PM
#5
Re: Help: Multiple Image, Single Picture Box...
Posted 21 July 2008 - 07:56 PM
I see, I see. I understand now.
#6
Re: Help: Multiple Image, Single Picture Box...
Posted 22 July 2008 - 03:37 AM
Hi Adam and Zhalix, thanks for trying to help me! I'm sorry about the mix up, I'm using VB6 but the tutorial I had to read to learn about image resources was for .NET so I may have gotten the terminology mixed up =[. I simply meant getting all 48 images added to one resource file, whatever that's called in VB6.
And to Zhalix, I really appreciate your answer! But I already know how to make a specific picture box load a specific picture at one time using loadpicture(""). But you mentioned counters! That's the part I needed help on~
How, specifically, do I write the runtime script so that:
When I click next, the picture box loads the next picture
When I click back, the picture box loads the previous picture
I really appreciate your guys' time and help, I'm trying my best to learn everything as fast as I can! Thanks again, hope to hear more soon~
And to Zhalix, I really appreciate your answer! But I already know how to make a specific picture box load a specific picture at one time using loadpicture(""). But you mentioned counters! That's the part I needed help on~
How, specifically, do I write the runtime script so that:
When I click next, the picture box loads the next picture
When I click back, the picture box loads the previous picture
I really appreciate your guys' time and help, I'm trying my best to learn everything as fast as I can! Thanks again, hope to hear more soon~
This post has been edited by Rannison: 22 July 2008 - 03:41 AM
#7
Re: Help: Multiple Image, Single Picture Box...
Posted 22 July 2008 - 05:27 AM
Honestly I don't know how to use a Resource file at all, much less use it for this purpose. If you must use it then I'm afraid my suggestions won't be of any use to you.
Anyway I suppose 'counter' really isn't the right word for it. It's just a number marker which designates the current image you're on. Now, keep in mind that this exact approach will only work if all your images are named the same thing, but with a different number.
Will work:
hdGah1.bmp
hdGah2.bmp
hdGah3.bmp
Won't work:
Cool.bmp
TheSun.bmp
Twix.bmp
First create a public variable at the top of your code of the integer data type. It will be our image marker.
Now, I'll show you how to create the file path. I'm gonna put it into a function but you don't have to. Start with the file path of an image in the directory you're going to be browsing, and remove it's number and everything to the right of it. Attach on intMarker, then attach on its extension:
Now give the intMarker an initial value in Form Load. In the Next button have it add one and in the Back button have it minus one from intMarker. You will load the images like this:
And that's it. Of course this is a very simple approach and it's missing out on some big bits of code (like how it deals with the image's dimensions) and it also has no error-checking so if the image doesn't exist it will simply crash the program.
Now, if your images aren't all named the exact same thing, you cannot use this method exactly. You will need to create a string array containing the filepaths of each image, and then you can use your number marker to cycle through the array's index to load the images.
Anyway I suppose 'counter' really isn't the right word for it. It's just a number marker which designates the current image you're on. Now, keep in mind that this exact approach will only work if all your images are named the same thing, but with a different number.
Will work:
hdGah1.bmp
hdGah2.bmp
hdGah3.bmp
Won't work:
Cool.bmp
TheSun.bmp
Twix.bmp
First create a public variable at the top of your code of the integer data type. It will be our image marker.
Dim intMarker As Integer
Now, I'll show you how to create the file path. I'm gonna put it into a function but you don't have to. Start with the file path of an image in the directory you're going to be browsing, and remove it's number and everything to the right of it. Attach on intMarker, then attach on its extension:
Private Function FilePath() As String FilePath = "C:\hdGah" & intMarker & ".bmp" End Function
Now give the intMarker an initial value in Form Load. In the Next button have it add one and in the Back button have it minus one from intMarker. You will load the images like this:
picGag.Picture = LoadPicture(FilePath)
And that's it. Of course this is a very simple approach and it's missing out on some big bits of code (like how it deals with the image's dimensions) and it also has no error-checking so if the image doesn't exist it will simply crash the program.
Now, if your images aren't all named the exact same thing, you cannot use this method exactly. You will need to create a string array containing the filepaths of each image, and then you can use your number marker to cycle through the array's index to load the images.
This post has been edited by Zhalix: 22 July 2008 - 06:00 AM
#8
Re: Help: Multiple Image, Single Picture Box...
Posted 29 May 2012 - 09:23 AM
Resource file is certainly a good approach for a form-based application, as it allows all of the images to be shipped in one .res file. To create and manipulate resource files, you'll need to add the Resource editor (resedit.dll) as an add-in. For more on this see here.
Adam, there's an ImageList control in VB6 too!
So, rannison, start with an ImageList control. Here's the doc for it. Store your images in this control, using the directions in the doc. Then, all you have to do to change the picture in your pictureBox control (you don't need a PictureBox control, consider using the lighter-weight Image control instead) to a new ImageList index each time you want to change the picture.
Chew on that a while, and post back if you need more help.
Finally, you're to be commended for taking responsibility for your own learning rather than asking us to do your work for you. If you keep that attitude, you'll always find people willing to help you.
Adam, there's an ImageList control in VB6 too!
So, rannison, start with an ImageList control. Here's the doc for it. Store your images in this control, using the directions in the doc. Then, all you have to do to change the picture in your pictureBox control (you don't need a PictureBox control, consider using the lighter-weight Image control instead) to a new ImageList index each time you want to change the picture.
Chew on that a while, and post back if you need more help.
Finally, you're to be commended for taking responsibility for your own learning rather than asking us to do your work for you. If you keep that attitude, you'll always find people willing to help you.
This post has been edited by BobRodes: 29 May 2012 - 09:26 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|