[ask]showing picture in background of a form ?

paul_heru

Member
Joined
Sep 27, 2005
Messages
14
Programming Experience
Beginner
retrieving picture from database and display in form

I have a problem with MDI form, and database, actually Im not sure to put this thread in WINDOWS FORM DISCUSSION, so here is the case, I just want to load a picture from database(image type, ini ms sqlserver database), after that the picture become the background of the MDI parentform. Anyone could tell me how ?, If u could, u can give the source code too, along with the description, thanks before
 
Last edited by a moderator:
Ok, can you change DB design as it is not good practice to keep images into DB (it makes you to have enormous growth of db size and also you need to perform conversion each time you want to show/display an image).
why you don't simply put only image's path there insted entire image? then all you need is to fetch the path and pass to form's backgroundimage property as JB says above.

Regards ;)
 
JuggaloBrotha said:
the only thing i know about this is that form's do have a BackgroundImage property
this is a part of my code, and it doesnt work

VB.NET:
Dim bw As BinaryWriter
Dim BufferSize As Integer = 100
Dim OutByte(BufferSize - 1) As Byte
Dim RetVal As Long
Dim StartIndex As Long = 0
Dim k As Integer = 0
Dim imag As Bitmap
cnn.Open()
                cmd = New SqlCommand("select System_Name,Logo from        Table_Company order by System_Name", cnn)
                sqlreader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)
                While sqlreader.Read

                    Dim fs As New IO.MemoryStream
                    bw = New BinaryWriter(fs)
                    StartIndex = 0
                    RetVal = sqlreader.GetBytes(1, StartIndex, OutByte, 0, BufferSize)
                    Do While RetVal = BufferSize
                        bw.Write(OutByte)
                        bw.Flush()
                        StartIndex += BufferSize
                        RetVal = sqlreader.GetBytes(1, StartIndex, OutByte, 0, BufferSize)
                    Loop
                    bw.Write(OutByte, 0, RetVal - 1)

                    imag = New Bitmap(fs)

                    bw.Flush()
                    bw.Close()
                    fs.Close()
                End While
                frm2.BackgroundImage = imag
                 cnn.Close()
ps :
cnn is sqlconnection class
frm2 is the mdi parent form
 
Last edited:
kulrom said:
Ok, can you change DB design as it is not good practice to keep images into DB (it makes you to have enormous growth of db size and also you need to perform conversion each time you want to show/display an image).
why you don't simply put only image's path there insted entire image? then all you need is to fetch the path and pass to form's backgroundimage property as JB says above.

Regards ;)

Sorry bro, i cant do that, cause the dbase i have just save the entire image into DB
 
Declare imag as public inside module or shared if you want to leave it inside current class Public Shared imag As Bitmap

read the image and when you call the intended form then pass "imag" as bgdImage:


VB.NET:
Dim frm2 As Form = New Form2
frm2.MdiParent = Me
frm2.BackgroundImage = imag
frm2.Show()


Regards ;)
 
kulrom said:
Declare imag as public inside module or shared if you want to leave it inside current class Public Shared imag As Bitmap

read the image and when you call the intended form then pass "imag" as bgdImage:


VB.NET:
Dim frm2 As Form = New Form2
frm2.MdiParent = Me
frm2.BackgroundImage = imag
frm2.Show()


Regards ;)

Bro , frm2 is not the mdichild, but the mdiparent, and the code suppose to be in the frm1 code area, and thanks for the link u gave on the other day, but it didnt work on my program, so Im still waiting for the solution.
 
Back
Top