hii all
i guess this is a simple problem but somehow i cant figure out the answer to it. i wrote a vb6 code which uses a particular software to draw a picture, saves it in the hard disk and then displays it in a picturebox.
now what i need is to display another picture in the same picturebox below the previous one.
any ideas?
thanks.

Dani AI

Generated

A compact, reliable pattern for stacking two images vertically without permanently eating screen space: compose them off‑screen into one image, then draw a viewport of that image into a fixed-size PictureBox and pan with a VScrollBar. That keeps the visible control small, avoids juggling multiple large visible PictureBoxes, and is easier than low‑level BitBlt for most cases. PaintPicture supports copying a source sub-rectangle into a destination control (so it can crop/scroll the big canvas). (learn.microsoft.com)

How it works (high level)

  • Create a hidden/off‑screen PictureBox (AutoRedraw = True) as the canvas.
  • Load each file with LoadPicture, convert each StdPicture Width/Height from HIMETRIC to pixels with ScaleX/ScaleY, then PaintPicture the first at Y=0 and the second at Y = firstHeight into the off‑screen box.
  • Persist the composed bitmap with Picture = Image (so it survives repaints) and use PaintPicture with srcY adjusted by the scrollbar to draw the visible viewport into the small on‑screen PictureBox. Note: StdPicture.Width/Height are in HIMETRIC, so convert before using pixel coordinates. (learn.microsoft.com)

Example (VB6 — sketch)

' picView = visible viewport; picBack = hidden off-screen PictureBox (AutoRedraw=True)
Private Sub Form_Load()
  Dim a As StdPicture, b As StdPicture
  Dim wA As Long, hA As Long, wB As Long, hB As Long, totalH As Long, totalW As Long

  Set a = LoadPicture(App.Path & "\img1.bmp")
  Set b = LoadPicture(App.Path & "\img2.bmp")

  picBack.ScaleMode = vbPixels
  wA = CInt(picBack.ScaleX(a.Width, vbHimetric, vbPixels))
  hA = CInt(picBack.ScaleY(a.Height, vbHimetric, vbPixels))
  wB = CInt(picBack.ScaleX(b.Width, vbHimetric, vbPixels))
  hB = CInt(picBack.ScaleY(b.Height, vbHimetric, vbPixels))

  If wA > wB Then totalW = wA Else totalW = wB
  totalH = hA + hB

  picBack.Width = totalW * Screen.TwipsPerPixelX
  picBack.Height = totalH * Screen.TwipsPerPixelY

  picBack.Cls
  picBack.PaintPicture a, 0, 0, wA, hA
  picBack.PaintPicture b, 0, hA, wB, hB
  picBack.Picture = picBack.Image  ' persist composed image

  picView.ScaleMode = vbPixels
  ' configure VScrollBar (vsb) so its range = totalH - picView.ScaleHeight, then call DrawViewport(vsb.Value)
End Sub

Private Sub DrawViewport(offsetY As Long)
  picView.Cls
  picView.PaintPicture picBack.Picture, 0, 0, picView.ScaleWidth, picView.ScaleHeight, _
                       0, offsetY, picView.ScaleWidth, picView.ScaleHeight
End Sub

Persisting the off‑screen composition and using PaintPicture for cropping is a standard VB6 technique (then SavePicture if you need to write the composed bitmap to disk). (vb-helper.com)

Troubleshooting & cautions

  • AutoRedraw = True allocates a memory bitmap; very large canvases can fail (runtime error 480). For huge source images prefer a tiled or scaled cache and only compose visible tiles. (learn.microsoft.com)
  • Keep ScaleMode consistent (use vbPixels) to avoid twips/pixels confusion.
  • If the images use transparency or require alpha, test formats — VB6’s handling varies; for complex masks you may still need a mask/BitBlt approach.

Credit: ’s idea of combining imagery is valid; the off‑screen + PaintPicture + scrollbar pattern keeps the UI compact and deterministic for stacking images vertically.

Recommended Answers

All 8 Replies

If you want to use the same picturebox to display 2 pictures, you'll have to find a way to make VB merge the two pictures in the format you want. Why can't they be different pictureboxes, made to look like one?

hmm thats a good idea.. why didnt i think of that..
thanks comatose.

well but there might be a small problem...
the first pic is quite large in size.. so for that to be displayed i have to make a picbox of that size which wud take most of the screen area.. so where do i put the next picbox.
wud that mean i need to put some vertical scroll bars.. but then there r 2 picboxes now.. so how do i manage that.
seems i m confused.
any help?

Ok, well, what exactly are you trying to accomplish? I mean, are you trying to display a picture, and then display another picture over it (like a watermark or logo)? You could always use bitblt and write both pictures to the same box, but you'll have to do quite a bit of trial and error to figure out where you want the other one to be placed.... let me know what you are doing, and I'll see what I can do.

no .. not over it.. but below the first picture.. they r two separate pictures.

Right, I get that, but what for? If you tell me what you are building, I might be able to come up with an alternative method of doing what you want....

EDIT: Here is a quick program that I threw together that has 3 picture boxes.... the main picturebox, and then the two pictures that get put into the 1 picturebox. So, picture2 and 3 contain the template pictures, and then you'll see in the code on form_load, that I use bitblt to load both pictures in the 1 picturebox, 1 directly beneath the other. You may want to play with the second bitblt a little, try changing it's Y position, or X position, and see how it looks and what it does. Anyway, here you go...

well i wrote a code which generates two pics using a software. all i want is to display them in a picturebox.
thanks for the code.. i will go thru it.

I want to trying to display a picture, and then display another picture over it (like a watermark or logo)?

Please help me;

My email address is; .

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.