标签:des style blog http color 使用 strong io
在一次做图片打印的时候,对位置的调整老是不得法,后来通过CBM666老师的帮助才解决问题,分享以下他给的帮助。
‘PaintPicture pic, destX, destY, destWidth, destHeight, scrX, scrY, scrWidth, scrHeight
‘其中Pic:为图片对象, 如图形框Picture等;
‘destX,destY:目标图像位置;
‘destWidth,destHeight:目标图像尺寸;
‘scrX,scrY:原图像的裁剪坐标;
‘scrWidth,scrHeight:原图像的裁剪尺寸;
Printer.PaintPicture picA.Picture, 200, 200, picA.Width / 2, picA.Height / 2
Printer.EndDoc
‘VB 打印图片
Private Sub Command1_Click()
On Error GoTo Err1
If Picture1.Picture <> LoadPicture("") Then
Printer.PaintPicture Picture1.Picture, 200, Picture1.Top + 1000 ‘打印图片
Else
MsgBox "没有可打印的图片", 16, "提示"
End If
Printer.EndDoc ‘打印结束
Exit Sub
Err1:
MsgBox Err.Description, 16, "提示" ‘错误处理
End Sub
Private Sub SetPrinterScale(obj As Object)
Dim pwid As Single, phgt As Single, xmid As Single, ymid As Single
Dim owid As Single, ohgt As Single
owid = obj.ScaleX(obj.ScaleWidth, obj.ScaleMode, vbTwips)
ohgt = obj.ScaleY(obj.ScaleHeight, obj.ScaleMode, vbTwips)
‘获取窗体以Twips表示的尺寸
pwid = Printer.ScaleX(Printer.ScaleWidth, Printer.ScaleMode, vbTwips)
phgt = Printer.ScaleY(Printer.ScaleHeight, Printer.ScaleMode, vbTwips)
‘获取打印机以Twips表示的尺寸
If (ohgt / owid > phgt / pwid) Then
s = phgt / ohgt
Else
s = pwid / owid
End If ‘‘计算缩放因子
pwid = obj.ScaleX(pwid, vbTwips, obj.ScaleMode) / s
phgt = obj.ScaleY(phgt, vbTwips, obj.ScaleMode) / s
‘将打印机的尺寸转换成obj的坐标系统 / 缩放因子
x_mid = obj.ScaleLeft + obj.ScaleWidth / 2
y_mid = obj.ScaleTop + obj.ScaleHeight / 2 ‘设置打印区域的中心点坐标
Printer.Scale (x_mid - pwid / 2, y_mid - phgt / 2)-(x_mid + pwid / 2, y_mid + phgt / 2)
‘设置打印机中新的ScaleWidth和ScaleHeight
End Sub
标签:des style blog http color 使用 strong io
原文地址:http://www.cnblogs.com/yhsc/p/3874240.html