Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]
Posted

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.

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...