zoukankan      html  css  js  c++  java
  • 解读PrintDocument 的PrintPage事件

    解读PrintDocument 的PrintPage事件

       PrintDocument 的PrintPage事件,他的执行方式是当 e.HasMorePages = True就执行一次PrintDocument 的PrintPage事件,直到e.HasMorePages = False时,才停止。

    下面是打印多个图片的代码:

     

    Private Sub PrintGraphicControl_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintGraphicControl.PrintPage
            Try
                'Dim XBegin As Integer
                'Dim YBegin As Integer
                'PicShow.fittoscreen()
                Dim ScaleParameter As Double '有可能放大也可能缩小
                Dim ImageInchCount As Double '图像英寸的数量
                Dim PaperInchCount As Double '图纸英寸的数量
                Dim Tmpimg As Image
            
                If StrFileName.Length - 1 = LstPicView.Items.Count Then
                    Tmpimg = Image.FromFile(StrFileName(CurrentPageNumber).Trim)
                    '当图像的宽度大于高度时,对图像进行旋转处理
                    If Tmpimg.Size.Width > Tmpimg.Size.Height Then
                        Tmpimg.RotateFlip(RotateFlipType.Rotate90FlipNone)
                    End If

                    '图像的高度/宽度比 >  图纸的高度/宽度比 时
                    '以高度填充整个图纸
                    If (Tmpimg.Size.Height / Tmpimg.Size.Width) > (e.PageSettings.PaperSize.Height / e.PageSettings.PaperSize.Width) Then
                        ImageInchCount = Tmpimg.Size.Height / 72 '英寸数
                        PaperInchCount = e.PageSettings.PaperSize.Height / 100 '英寸数
                        ScaleParameter = PaperInchCount / ImageInchCount
                        '图像的高度/宽度比  <=  图纸的高度/宽度比 时
                        '以宽度填充整个图纸
                    Else
                        ImageInchCount = Tmpimg.Size.Width / 72
                        PaperInchCount = e.PageSettings.PaperSize.Width / 100
                        '当图像英寸的高度大于纸张英寸的高度时
                        ScaleParameter = PaperInchCount / ImageInchCount
                    End If

                    Dim imgnew As New System.Drawing.Bitmap(Tmpimg, CInt(Tmpimg.Size.Width * ScaleParameter), CInt(Tmpimg.Size.Height * ScaleParameter)) '新建一个放大的图片

                    e.Graphics.DrawImage(imgnew, e.MarginBounds)
                    'e.Graphics.DrawImage(imgnew, e.Graphics.VisibleClipBounds)
                    CurrentPageNumber = CurrentPageNumber + 1
                    If CurrentPageNumber <= PageCount Then
                        e.HasMorePages = True
                    Else
                        e.HasMorePages = False
                    End If
               
                End If
            Catch ex As Exception
            End Try
        End Sub

  • 相关阅读:
    DB2开发系列之三——SQL函数
    DB2开发系列之二——SQL过程
    DB2开发系列之一——基本语法
    优化的“真谛”
    DB2性能调优
    AIX分页(交换)空间的监控
    AIX5L内存监控和调整
    直接删除undo及temp表空间文件后的数据库恢复一例
    【LeetCode】 -- 68.Text Justification
    关于linux下的.a文件与 .so 文件
  • 原文地址:https://www.cnblogs.com/yuxuetaoxp/p/1784299.html
Copyright © 2011-2022 走看看