回 帖 发 新 帖 刷新版面

主题:打印不换页的问题

用以下的程序打印不能换页,需打印的内容会打印同一张纸上,请高手指点指点!
Sub pd_print(ByVal sender As Object, ByVal e As PrintPageEventArgs)

        Dim fnt, fnt1 As Font
        fnt = New Font("黑体", 13)
        fnt1 = New Font("黑体", 15)
        e.PageSettings.Margins.Top = 0
        e.PageSettings.Margins.Left = 0
        Dim i, a As Long
        a = 14 ' 需打印的证数
        Dim f As String
        Dim k As Short = 0 '打印行
        Dim ycd As Short '打印的位置  
                For i = 1 To a
                    ycd = 70 + k * 275
                    k = k + 1
                    f = CStr(ycd) + "_" + CStr(i)
                    e.Graphics.DrawString(f, fnt, Brushes.Black, 22, ycd)
                    If ycd > 900 Then
                        k = 0
e.HasMorePages = True
                    End If
                Next              
                e.HasMorePages = False
                fnt.Dispose()
    End Sub

    Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim pd As New PrintDocument
        AddHandler pd.PrintPage, AddressOf Me.pd_print
        pd.Print()
    End Sub   
End Class




共有0回帖 当前第1页(共1页)  1      
      

回复列表 (共4个回复)

沙发

你没有设置打印纸型,那就默认是A4

想要按要求换页就得自定义或者选择合适的纸型

板凳

我使用e.PageSettings.PaperSize = paper.a4,程序不认,请教大侠,应如何设置才对,谢!

3 楼

e.PageSettings.PaperSize.Kind.A4

4 楼

以下示例用指定的打印机打印文档。该示例有三个假定:已经将名为 filePath 的变量设置为要打印的文件的路径;已经定义名为 pd_PrintPage 的方法(该方法处理 PrintPage 事件);已经将名为 printer 的变量设置为打印机的名称。

[Visual Basic, C#] 在此示例中使用 System.Drawing、System.Drawing.Printing 和 System.IO 命名空间。


Public Sub Printing(printer As String)
    Try
        streamToPrint = New StreamReader(filePath)
        Try
            printFont = New Font("Arial", 10)
            Dim pd As New PrintDocument()
            AddHandler pd.PrintPage, AddressOf pd_PrintPage
            ' Specify the printer to use.
            pd.PrinterSettings.PrinterName = printer

            If pd.PrinterSettings.IsValid then
               pd.Print()
            Else
               MessageBox.Show("Printer is invalid.")
            End If
        Finally
            streamToPrint.Close()
        End Try
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub

我来回复

您尚未登录,请登录后再回复。点此登录或注册