none
PrintDocument與分頁問題 RRS feed

  • 問題

  •  

    請教各位大大~

                           當我使用printdocument產生我要列印的畫面(抓文字檔),目前單頁都OK,但是當我資料超過一頁,就會有問題,我想請教各位大大...

    1. 我要怎樣才可以新增新頁面 ,並且把多出第一頁的資料,加到第二頁去??
    2. 用Printdocument +PrintPreviewDialog1他會一直預覽到十幾頁去,但是我資料並不會多到第三頁去

     

    PS:

     

    e.HasMorePages 好像不是這樣用,他是指有下一頁就會跳第二頁去印

     

    環境:VB.NET 2005

    Printdocument + PrintPreviewControl

     

     

     

     

    Code Snippet

        Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

    Dim G As Graphics = e.Graphics
            G.DrawString("盤點差異表", New Font("新細明體", 30, FontStyle.Underline), Brushes.Black, 300, 10)
            G.DrawString("盤點日期: " + Now.ToString, New Font("新細明體", 10, FontStyle.Underline), Brushes.Black, 550, 80)
            Dim TitleFont As Font = New Font("新細明體", 20, FontStyle.Bold)
            G.DrawString("倉別", TitleFont, Brushes.Black, 40, 120)  '倉別字串
            G.DrawString("布號", TitleFont, Brushes.Black, 200, 120) '布號字串
            G.DrawString("批號", TitleFont, Brushes.Black, 380, 120) '批號字串
            G.DrawString("碼數", TitleFont, Brushes.Black, 530, 120) '碼數字串
            G.DrawString("狀態", TitleFont, Brushes.Black, 700, 120) '狀態字串
            G.DrawLine(New Pen(Color.Black, 2), 10, 150, 800, 150)   '標題線

            Dim ListFont As New Font("新細明體", 16, FontStyle.Bold)

            Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("c:\ids\pre\pre.txt")
                MyReader.TextFieldType = FileIO.FieldType.Delimited
                MyReader.Delimiters = New String() {","}

                Dim Y As Integer = 160 'Y座標
                'MyReader.ReadLine()
                While Not MyReader.EndOfData
                    'MyReader.ReadLine()
                    Data = MyReader.ReadFields
                    G.DrawString(Data(0), ListFont, Brushes.Black, 35, Y)
                    G.DrawString(Data(1), ListFont, Brushes.Black, 195, Y)
                    G.DrawString(Data(2), ListFont, Brushes.Black, 375, Y)
                    G.DrawString(Data(3), ListFont, Brushes.Black, 525, Y)
                    Select Case Data(4)
                        Case "0" '印出缺
                            G.DrawString("缺", ListFont, Brushes.Black, 705, Y)
                        Case "1" '無用處理
                            G.DrawString("不用處理", ListFont, Brushes.Black, 705, Y)
                        Case "2"
                            G.DrawString("多", ListFont, Brushes.Black, 705, Y)
                        Case "3"
                            G.DrawString("改", ListFont, Brushes.Black, 705, Y)
                    End Select
                    Y += 25

                    If Y <= 1100 Then
                        '小於一頁
                        e.HasMorePages = False
                    Else
                        e.HasMorePages = True
                        'Y = 0
                        '大於一頁(A4)
                    End If

     

     

    2008年9月18日 上午 02:21

解答

所有回覆