• 0

[VB.NET] Ask For Image Location


Question

Hi,

I'm currently working on a program that automaticly adds pictureboxes whenever you add an entree to a database (access).

I got that working, but Now I'm wondering how you make the picturebox (or whatever) ask where the image is located to draw it in the picturebox.

Example:

Database:

tblAnimals contains

- Dog

- Cat

Now in my form it auto adds 2 pictureboxes without containing any images. Now it should ask for the image location (C/Document/Pictures/Dog.jpg) and draw that in the picturebox.

I have no idea how to this, anyone has any ideas?

Already thx :)

This is my acctual code now:

		Dim bytTeller As Byte
		Dim objdtsProducten As New dtsProducten
		Dim objtblProductenTA As New dtsProductenTableAdapters.tblProductenTableAdapter
		Dim dtrProduct As dtsProducten.tblProductenRow

		objtblProductenTA.Fill(objdtsProducten.tblProducten)

		For Each dtrProduct In objdtsProducten.tblProducten

			Dim ptbKnop As New PictureBox

			ptbKnop.Name = dtrProduct.ProductID
			ptbKnop.Text = dtrProduct.ProductNaam
			ptbKnop.Size = New Size(80, 40)
			ptbKnop.Location = New Point((bytTeller Mod 4) * 90, (bytTeller \ 4) * 50)

			AddHandler ptbKnop.Click, AddressOf KnopGeklikt
			Me.Controls.Add(ptbKnop)
			bytTeller += 1
		Next

I know I can open a picture with this:

With OpenFileDialog1
			.CheckFileExists = True
			.ShowReadOnly = False
			.Filter = "All Files|*.*|Bitmap Files (*)|*.bmp;*.gif;*.jpg"
			.FilterIndex = 2
			If .ShowDialog = DialogResult.OK Then
				' Load the specified file into a PictureBox control.
				Dog.Image = Image.FromFile(.FileName)
			End If
		End With

But I don't know the name of the picture yet (see DOG)

Edited by Guest
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

I know nothing about VB.NET, but I giggled when I read your problem, then example.. You want to enter an entree into the database, and your examples are cat and dog. :D

Link to comment
Share on other sites

  • 0

Don't "ask" where the image is, use fileupload to let the user browse for an image. Code the submit to copy the file to server folder and record image path to db. Then, just set the src of the image to the db path entry.

Link to comment
Share on other sites

  • 0

In the table, are you storing the image itself, or perhaps a path to the image (not recommended)? If you are storing the byte content of the image, you can open it into a stream and load the stream into the picturebox.

From how I've read your problem, you have a form which lists records from the database, and you want it to show you a picture associated with that record.

Could you post your project (zipped), or PM me, and we'll have a look.

Rohdekill: He's not doing ASP.NET mate, he's using Winforms, so he doesn't have the file upload control.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.