zoukankan      html  css  js  c++  java
  • 如何打印ListView里的内容

    需在用到的对象有PrintDocument,PrintPreviewControl

    指定要打印的字体;

        Dim printFont As Font = New Font("宋体"10)
    初始化PrintPreviewControl1

      ' Construct the PrintPreviewControl.
            Me.PrintPreviewControl1 = New Windows.Forms.PrintPreviewControl


            
    ' Set location, name, and dock style for PrintPreviewControl1.
            Me.PrintPreviewControl1.Location = New Point(8880)
            
    Me.PrintPreviewControl1.Name = "PrintPreviewControl1"
            
    Me.PrintPreviewControl1.Dock = DockStyle.Fill

            
    ' Set the Document property to the PrintDocument 
            ' for which the PrintPage event has been handled.
            Me.PrintPreviewControl1.Document = docToPrint

            
    ' Set the zoom to 25 percent.
            Me.PrintPreviewControl1.Zoom = 1

            
    ' Set the document name. This will show be displayed when 
            ' the document is loading into the control.

            
    ' Set the UseAntiAlias property to true so fonts are smoothed
            ' by the operating system.
            Me.PrintPreviewControl1.UseAntiAlias = True

            
    Me.PrintPreviewControl1.Rows = 5 '纵向显示五页,用于调试

            
    ' Add the control to the form.
            Me.Controls.Add(Me.PrintPreviewControl1)
    PrintDocument的PringPage事件

        
    Private Sub docToPrint_PrintPage(ByVal sender As ObjectByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles docToPrint.PrintPage
            
    Dim linesPerPage As Single = 0
            
    Dim yPos As Single = 0
            
    Dim count As Integer = 0
            
    Dim leftMargin As Single = e.MarginBounds.Left '左边距
            Dim topMargin As Single = e.MarginBounds.Top    '右边距
            Dim line As String = Nothing

            
    ' Calculate the number of lines per page.
            linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)


            
    Static starRow As Integer
            
    Dim row As Integer


            
    For row = starRow To Me.lv.Items.Count - 1

                
    If count > linesPerPage Then
                    starRow 
    = row
                    
    Exit For
                
    End If

                
    Dim item = Me.lv.Items(row)
                yPos 
    = topMargin + count * printFont.GetHeight(e.Graphics)

                
    Dim x As Single = leftMargin
                
    For m As Integer = 0 To item.SubItems.Count - 1
                    x 
    += Me.lv.Columns(m).Width
                    line 
    = item.SubItems(m).Text
                    e.Graphics.DrawString(line, printFont, Brushes.Black, x, yPos, 
    New StringFormat())
                
    Next

                count 
    += 1
            
    Next

            
    If row = Me.lv.Items.Count Then
                e.HasMorePages 
    = False
            
    Else
                e.HasMorePages 
    = True
            
    End If


        
    End Sub
    此示例,不能打印表格线!
  • 相关阅读:
    中文转拼音 (utf8版,gbk转utf8也可用)
    会不会死循环
    图片放大缩小的zoom.js
    Getting unknown property: commonmodelsTeacher::auth_Key
    Yii-admin 权限菜单配置
    wordpress 后台富文本编辑器,添加图片发现无法左对齐,样式出现混乱
    windows 命令
    Yii2 获取URL的一些方法
    PHP 直接使用html输出excel
    json JSON_UNESCAPED_UNICODE 防止中文乱码
  • 原文地址:https://www.cnblogs.com/zqonline/p/1610721.html
Copyright © 2011-2022 走看看