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

  • 相关阅读:
    How to create Ubuntu Image with Linaro Image Tools
    linux little tool
    Firefly-RK3288
    tensorflow 出现KeyError: 'tulips\8689672277_b289909f97_n.jpg'报错
    开发中涉及的框架与工具
    这三年被分布式坑惨了,曝光十大坑 【转载】
    C#动态编译及执行代码
    cron表达式可视化编辑页面
    AVPacket相关函数介绍
    ffmpeg 重要函数介绍
  • 原文地址:https://www.cnblogs.com/yuxuetaoxp/p/1784299.html
Copyright © 2011-2022 走看看