daveydave400 Posted October 29, 2005 Posted October 29, 2005 Alright I have a program with a combobox thats items are based on how many files in a certain directory have a certain part of a name and extension. So basically it says: If ComboBox2.SelectedItem = ("Baths Style A") Then ComboBox3.Items.Clear() ComboBox3.Text = ("Choose the Picture") Dim exedir As String = CurDir() Dim x As String = 1 For Each filename As String In Directory.GetFiles(exedir & "\BATHS & POWDER ROOMS", "BathA*.jpg") ComboBox3.Items.Add("Bath Style A " & x) x = x + 1 Next End If So basically I was wondering if anyone could help me with maybe an example of how to give each item, the picture that it represents. So when you clicked on "Bath Style A 1" it would show the first picture it found in a picturebox. I am not using an imagelist because of the poor quality of the images. I would like to use the "System.Drawing.Bitmap.FromFile" command if possible. So if anyone could give me and example or tutorial on how to do this that would be great. I would rather not have someone give me the exact answer (I'm learning from my last post). Any help is greatly appreciated, Thanks. Quote
Leaders snarfblam Posted October 29, 2005 Leaders Posted October 29, 2005 You would need to keep track of filenames, of course. This could be done with an arraylist. 'Class scope variable Dim FileNames As New ArrayList 'Within your function If ComboBox2.SelectedItem = ("Baths Style A") Then ComboBox3.Items.Clear() FileNames.Clear() 'Clear our list of filenames ComboBox3.Text = ("Choose the Picture") Dim exedir As String = CurDir() Dim x As String = 1 For Each filename As String In Directory.GetFiles(exedir & "\BATHS & POWDER ROOMS", "BathA*.jpg") ComboBox3.Items.Add("Bath Style A " & x) x = x + 1 FileNames.Add(Io.Path.Combine(exedir & "\\Baths & Powder rooms\\",Filename)) Next End If Then, when a combo item is selected, you can retrieve the assiciated filename by index and use the bitmap constructor to create the image. MyPictureBox.Image = New Bitmap(FileNames(MyCombo.SelectedIndex).ToString) I didn't test the code but it should give you a good idea of what to do. Quote [sIGPIC]e[/sIGPIC]
daveydave400 Posted October 30, 2005 Author Posted October 30, 2005 Thanks Anyway Well I'm sure that does work but I don't know how to use arrays and I dont have the patience to learn right now, not to sound disrespectful but I just used the Combobox3.selectedindex number as a reference as to what picture it uses. So like: If ComboBox2.SelectedItem = ("Baths Style A") Then PictureBox1.Image = Nothing ComboBox3.Items.Clear() ComboBox3.Text = ("Choose the Picture") Dim exedir As String = CurDir() Dim x, y As String x = 1 y = 0 For Each filename As String In Directory.GetFiles(exedir & "\BATHS & POWDER ROOMS", "BathA*.jpg") ComboBox3.Items.Insert(y, "Bath Style A " & x) x = x + 1 y = y + 1 Next End If It might not be as convenient and it doesnt work if the first picture or anypicture is deleted. Quote
Leaders snarfblam Posted October 30, 2005 Leaders Posted October 30, 2005 Well... there really isn't any learning involved there. Despite the posting guidelines, I basically handed you the code you need. Understanding and learning aren't requisites. You really ought to take the time to learn something as elementry as arrays, though. Also note that you can change the color depth and image size for the ImageList. If you set the color depth to 24 or 32 bit and set the size to that of your picutre box, you will most likely not see any loss of quality. Quote [sIGPIC]e[/sIGPIC]
daveydave400 Posted November 1, 2005 Author Posted November 1, 2005 Gotcha Well about the learning thing I am in class right now so I'm just waiting for that to come up. But about the imagelist thing yeah I tried that a little bit but I jsut thought it looked better. I put it to like the largest size you could and the 32 bit I think it was and it was a little off but I'm sure if I knew what I was doing it would have worked but I'm not trying to be a genious right now but yeah thanks everyone for the help. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.