但是,我们在打印时,经常会遇到这样的场合——在不改变窗体形状的情况下,需要扩大或缩小窗体的大小。要完成这样的工作,不仅需要完成属性匹配,还要确定对象被缩放的系数。程序如下:
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
⑹ 坐标定位
1、Rod Steprhens Visual BasicTM Graphics Programming
2、温志华王显文 徐强 ·Visual Basic 6.0 多媒体实用编程技术· 1999
3、张树兵等·Visual Basic 6.0中文版入门与提高·清华大学出版社,1999