简体   繁体   中英

How can I show a picture on a form in VB.NET?

I am creating questionnaires using VB.NET and SQL and my problem now is how can I show an image already present in the database onto a form? Please note that as the form is a questionnaire, it is navigable by the means of going up or down rows in a dataset. For example when the NEXT button is clicked, the row in the dataset goes +1. So how should I go about coding it in order to display an image onto the form?

this is the code how i saved the image

Dim ms As New MemoryStream()
PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
Dim data As Byte() = ms.GetBuffer()
Dim x As New SqlParameter("@image", SqlDbType.Image)
x.Value = data
cmd.Parameters.Add(x)

And the code for navigating between rows of a dataset in a single form:

RichTextBox1.Text = dsquestionnaire.Tables(0).Rows(qsno).Item("Question") .....

qsno + 1 (As a part of the NEXT button click event)

Thanks in advance..

You can load the image from the DB into your picture box as follows:

Using ms As New IO.MemoryStream(CType(row("image", Byte()))

Dim img As Image = Image.FromStream(ms)
Image1.Image = img

For the click event you can place this inside a method and just call it to load the image into the Picture box when the next button is clicked

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM