|
欢迎来到月影社区!如果您觉得这里不错,请推荐给您的朋友们。月影社区:http://wf66.com/ |
VB打印预览-上
|
|
Option Explicit
Private Sub Form_Load() CommonDialog1.CancelError = True Command1.Caption = "Load Picture" Command2.Caption = "Print Preview" Command3.Caption = "Print" End Sub
Private Sub Command1_Click() Dim sFileFilter As String
On Error GoTo ErrHandler
sFileFilter = "Bitmap Files (*.bmp)|*.bmp|" sFileFilter = sFileFilter & "GIF Files (*.gif)|*.gif|" sFileFilter = sFileFilter & "Icon Files (*.ico)|*.ico|" sFileFilter = sFileFilter & "JPEG Files (*.jpg)|*.jpg|" sFileFilter = sFileFilter & "Windows MetaFiles (*.wmf)|.wmf" With CommonDialog1 .Filter = sFileFilter .ShowOpen If .FileName <> " " Then Picture2.Picture = LoadPicture(.FileName) End If End With
ErrHandler: Exit Sub End Sub
Private Sub Command2_Click() Dim dRatio As Double dRatio = ScalePicPreviewToPrinterInches(Picture1) PrintRoutine Picture1, dRatio End Sub
Private Sub Command3_Click() Printer.ScaleMode = vbInches PrintRoutine Printer Printer.EndDoc End Sub
Private Function ScalePicPreviewToPrinterInches _ (picPreview As PictureBox) As Double
Dim Ratio As Double ' Ratio between Printer and Picture Dim LRGap As Double, TBGap As Double Dim HeightRatio As Double, WidthRatio As Double Dim PgWidth As Double, PgHeight As Double Dim smtemp As Long
' Get the physical page size in Inches: PgWidth = Printer.Width / 1440 PgHeight = Printer.Height / 1440
' Find the size of the non-printable area on the printer to ' use to offset coordinates. These formulas assume the ' printable area is centered on the page: smtemp = Printer.ScaleMode Printer.ScaleMode = vbInches LRGap = (PgWidth - Printer.ScaleWidth) / 2 TBGap = (PgHeight - Printer.ScaleHeight) / 2 Printer.ScaleMode = smtemp
' Scale PictureBox to Printer's printable area in Inches: picPreview.ScaleMode = vbInches
' Compare the height and with ratios to determine the ' Ratio to use and how to size the picture box: HeightRatio = picPreview.ScaleHeight / PgHeight WidthRatio = picPreview.ScaleWidth / PgWidthVB打印预览-上 |
[ 1 ] |
|
VB打印预览-上 num |
【打印本页
关闭】 |
|