CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2009
    Posts
    26

    help with picture box

    Hello and good day...

    I need to create a picturebox that allows different pics to show when The user clicks an item in a combo box. in vb.net.....


    Any help on how to go about it is welcomed

  2. #2
    Join Date
    Aug 2009
    Posts
    12

    Post Re: help with picture box

    Hello, i have done a sample code for you.

    Instructions
    1. Pull a ComboBox (named ComboBox1) and a PictureBox (named PictureBox1) to the form
    2. Copy the following code to the editor
    3. Change the directory path that contains the images.



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim dirInfo As New System.IO.DirectoryInfo("C:\Users\Public\Pictures\Sample Pictures")

    ComboBox1.DataSource = dirInfo.GetFiles("*.jpg")
    ComboBox1.DisplayMember = "Name"
    ComboBox1.Refresh()

    UpdatePicture()
    End Sub

    Private Sub UpdatePicture()
    If ComboBox1.SelectedIndex < 0 Then Exit Sub

    Dim f As System.IO.FileInfo
    f = CType(ComboBox1.SelectedItem, System.IO.FileInfo)

    PictureBox1.Image = System.Drawing.Image.FromFile(f.FullName)
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    UpdatePicture()
    End Sub

  3. #3
    Join Date
    Jul 2009
    Posts
    26

    Re: help with picture box

    Thanks I got that working .... I already have a list of items in my combobox and I want Images to occur in the picture box area once its click........

  4. #4
    Join Date
    Aug 2009
    Posts
    12

    Re: help with picture box

    Have you copy this sub to the code editor

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

    Having this event, the picture box should load the picture when the combox item selection is changed.

    By the way, what are your images extension?

  5. #5
    Join Date
    Jul 2009
    Posts
    26

    Re: help with picture box

    Thanks I have it solved already

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured