hello!!! i would really appreciate a little help. here's the deal: i have a folder with some fotos in it. all i'm trying to do is make a program in whitch you can write the name of a foto in a textbox, click the "Search" button and find that picture in that folder and then show it in a picturebox in the form.(the program will search only in one specific folder)

i used PictureBox1.ImageLocation but that only shows the foto you specify in the command.

i hope you understand what i want to say.

thanks!!

Recommended Answers

All 9 Replies

I didn't got it.

You want something like... write a name inside a textbox, hit search and it will show the image on the textbox?

You might use this:

PictureBox1.Image = Image.FromFile("path\to\image")

Hope it helps.

actually i want to write a name inside a textbox, hit search and it will show the image on a picturebox.

For the picturebox, use the code I've show above.

Chance a bit. From this:

PictureBox1.Image = Image.FromFile("path\to\image")

To this:

PictureBox1.Image = Image.FromFile(Textbox1.Text)

It should work. But you'll need to have previously defined some values, like folder path and a extension. So, I think that storing it into a variable is nice. Try this:

Dim path as String = "C:\my folder\" 'sets the folder. remember to use quotes.
Dim extension as string = ".jpg" 'sets the file extension. also, remember to use quotes
Dim image as String = "" 'it will store the full file path

image = path + Textbox1.Text + extension
PictureBox1.Image = Image.FromFile(image) 'now without quotes, 'cause we're referencing a variable

Search engine I'll left for someone else that knows how to do it (:

Hope it helps!

yes yes yes i understood what you said!! you're right it should work but it gives me an error on line

6: PictureBox1.Image = Image.FromFile(image)

it says 'FromFile' is not a member of 'String' :S

Can you post your full code? It would help a lot (:

ok then. i got a PictureBox1,TextBox1 and Button1

and i got this:

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim st As String
  3. Dim path As String = "F:\My Office\Foto Database"
  4. Dim extension As String = ".jpg"
  5. Dim image As String
  6. st = TextBox1.Text
  7. image = path + st + extension
  8. PictureBox1.Image = image.FromFile(image)
  9. End Sub

So sorry! I haven't noticed that I've named the variable with the same name as a function.

Here is the correct code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim st As String
        Dim path As String = "E:\Fotos\"
        Dim extension As String = ".jpg"
        Dim imagepath As String
        st = TextBox1.Text
        imagepath = path + st + extension
        MsgBox(imagepath)
        PictureBox1.Image = Image.FromFile(imagepath)
    End Sub

The MsgBox I use only for debugging purposes. Also, the textbox can't be empty, otherwise it'll give a error.

Edit: Remember to edit you path variable.

Edit2: Here is a little updated code:

Public Class Form1
    Dim st As String
    Dim path As String = ""
    Dim extension As String = ".jpg"
    Dim imagepath As String


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        st = TextBox1.Text
        imagepath = path + "\" + st + extension
        If IO.File.Exists(imagepath) = True Then
            PictureBox1.Image = Image.FromFile(imagepath)
        Else
            MsgBox("File doesn't exist!")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        FolderBrowserDialog1.ShowDialog()
        path = FolderBrowserDialog1.SelectedPath
        TextBox2.Text = FolderBrowserDialog1.SelectedPath
    End Sub
End Class

Add to your form a new textbox, a new button and a file browser dialog. The new textbox will be the path, the new button will open the browse dialog box. You'll need to use the browse dialog, just typing into the textbox will not work (otherwise you implement it, its pretty easy).

I think that's all!

It did work!!!!!! You are the man!!!!!! Thank you so muchhh!!!!!!!!!!!!!!!!!

You're welcome! Don't forget to mark this thread as solved (:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.