09-08-2003, 05:02 PM
This is probably simple but I can't figure it out, and I was hoping someone could explain it to me. I have an image and I want to, at
run time, decide where I want it to appear on a picture box. It might end up in the middle of the picbox, or in the bottom corner, or ....
Any help would be greatly appreciated!
09-08-2003, 05:06 PM
Try the PaintPicture method of the picturebox
09-08-2003, 09:37 PM
I think you just want to put an image control in the picture box. You
load the image into the image control, and then you can change it's
.left and .top, to reposition the image, where ever you want.
09-08-2003, 10:52 PM
Without using an extra control you can do this to center the picture. Vary to code to place the image where you like.
.Render Picture1.hDC, 0, 0, iWidth, iHeight... would be top left
Private Sub Form_Load()
CenterPicture "c:\foo.bmp", Picture1
' begin modRender.bas
Public Sub CenterPicture(ByVal sFileName As String, ByVal pic As PictureBox)
Dim p As Picture
Dim iWidth As Integer
Dim iHeight As Integer
Set p = LoadPicture(sFileName)
iWidth = pic.ScaleX(p.Width, vbHimetric, vbPixels) ' Image width
iHeight = pic.ScaleY(p.Height, vbHimetric, vbPixels) ' Image height
.ScaleMode = vbPixels
.AutoRedraw = True ' or use False and .Render in the Paint Event
p.Render .hDC, (.ScaleWidth - iWidth) \ 2, (.ScaleHeight - iHeight) \ 2, iWidth, iHeight, 0, p.Height, p.Width, -p.Height, ByVal 0
Set p = Nothing