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
    此示例,不能打印表格线!
  • 相关阅读:
    Lambda表达式介绍 dodo
    VS2010引用App_Code下的类文件问题解决方法(转) dodo
    读取EXCEL文件数字类型字段为空的问题 dodo
    sql server 2000:不能打开到主机的连接,在端口1433:连接失败 dodo
    sql2008附加数据库只读解决办法 dodo
    js倒计时跳转页面 dodo
    orchard上传文件提示System.Web.HttpException: 超过了最大请求长度 dodo
    SQLServer2008设置 开启INTERNET远程连接(转) dodo
    SQLSERVER2008端口改变后的远程连接和数据库连接 dodo
    无法生成临时类(result=1) dodo
  • 原文地址:https://www.cnblogs.com/zqonline/p/1610721.html
Copyright © 2011-2022 走看看