Hi all,

I have a picturebox with scalemode pixel

dim height as integer
dim width as integer

height = picbox.scaleHeight
width = picbox.scaleWidth

picbox.PaintPicture pic, 0, 0, height, width, 0, 0, picheight, picwidth

note: picheight and picwidth are the height and the width of pic (in pixel) that has been calculated with autosize picturebox in other form.

My problem is: the picture cannot be drawn for the entire picturebox... there is a gap on the right and bottom in the picturebox... why is it happens?

Note: my project is to zoom out the pic... to fit the picbox


7 Years
Discussion Span
Last Post by neosonic

scalemode the same for all? because this works (as a test)

Picture2.PaintPicture Picture1.Picture, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight

and picture2 is set at double the size of picture1...

Properties changed at design time
ScaleMode = vbPixels
Picture1.AutoSize = True 'while picture2.autosize = false

Good Luck


The problem is from Height to ScaleHeight and ScaleHeight to Height

Get the Height and Width of the Image from the Picture object rather than from AutoSize

To Get the Height and Width of the Image

Private Sub Form_Load()
   Dim img As StdPicture
   Set img = LoadPicture("abc.jpg")
   'Image Height and Width is in HiMetrix Unit and Change it to Pixel
   MsgBox (" Height = " & HiMetrixToPixelY(img.Height) & " px Width = " & HiMetrixToPixelX(img.Width) & " px")
End Sub

'Function to Change Height from HiMetrix to Pixel
Private Function HiMetrixToPixelY(yHiM) As Long
   HiMetrixToPixelY = Me.ScaleY(yHiM, vbHimetric, vbPixels)
End Function
'Function to Change Width from HiMetrix to Pixel
Private Function HiMetrixToPixelX(xHiM) As Long
   HiMetrixToPixelX = Me.ScaleX(xHiM, vbHimetric, vbPixels)
End Function

I have shown u to convert one unit to another

The Problem may be from PaintPicture method call
Syntax is
PaintPicture picture, x1, y1, destWidth, destHeight, x2, y2, srcWidth, srcHeight, opcode

But u have interchanged the parameters width for height and height for width in the picbox.PaintPicture pic, 0, 0, height, width, 0, 0, picheight, picwidth I hope this may help u

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.