2015-12-07 219 views
0

如何打印多個頁面?在我的表格中,我有帶相應標籤的文本框。 (ID,名稱,課程等),但問題是1頁是不夠顯示所有文本框。我必須添加另一個頁面來顯示剩餘的文本框及其標籤。我嘗試將e.hasmorepages設置爲true,但第二頁中顯示的文本框與第一頁中的文本框不一樣。在vb.net中打印多個頁面

這裏是我的代碼:

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

    Dim labelFont As New Font("Arial", 11, FontStyle.Bold) 
    Dim textFont As New Font("Arial", 11, FontStyle.Regular) 
    Dim headerFont As New Font("Arial", 12, FontStyle.Bold) 

    e.Graphics.DrawString(lblGrade.Text, headerFont, Brushes.Black, 650, 660) 
    e.Graphics.DrawString(grade11.Text, textFont, Brushes.Black, 660, 690) 
    e.Graphics.DrawString(underline.Text, labelFont, Brushes.Black, 643, 692) 
    e.Graphics.DrawString(grade12.Text, textFont, Brushes.Black, 660, 715) 
    e.Graphics.DrawString(grade13.Text, textFont, Brushes.Black, 660, 740) 
    e.Graphics.DrawString(grade14.Text, textFont, Brushes.Black, 660, 765) 
    e.Graphics.DrawString(grade15.Text, textFont, Brushes.Black, 660, 790) 
    e.Graphics.DrawString(grade16.Text, textFont, Brushes.Black, 660, 815) 
    e.Graphics.DrawString(grade17.Text, textFont, Brushes.Black, 660, 840) 
    e.Graphics.DrawString(grade18.Text, textFont, Brushes.Black, 660, 865) 
    e.Graphics.DrawString(grade19.Text, textFont, Brushes.Black, 660, 890) 
    e.Graphics.DrawString(grade20.Text, textFont, Brushes.Black, 0, 1500) 

    mPageNumber += 1 

    e.HasMorePages = (mPageNumber <= 2) 
End Sub 
+1

[http://stackoverflow.com/questions/16945172/printing-multiple-pages-with-printdocument](http://stackoverflow.com/questions/16945172/printing-multiple-pages-with- printdocument) –

回答

0

當你有多個頁面,你需要確保你的單身PrintPage()方法一次爲每個需要打印頁面調用。每次調用該方法時,都需要知道當前頁面是什麼以及需要將哪些內容寫入該頁面。

你的e.HasMorePages變量是你如何讓你的PrintDocument對象再次調用該方法。另外請記住,您的printSisDoc_PrintPage()方法是一個類的一部分。您需要在方法中可以使用的類中設置數據,以瞭解哪些頁面是最新的以及要打印的內容。

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

    Dim labelFont As New Font("Arial", 11, FontStyle.Bold) 
    Dim textFont As New Font("Arial", 11, FontStyle.Regular) 
    Dim headerFont As New Font("Arial", 12, FontStyle.Bold) 

    Select mPageNumber 
    Case 1 
     e.Graphics.DrawString(lblGrade.Text, headerFont, Brushes.Black, 650, 660) 
     e.Graphics.DrawString(grade11.Text, textFont, Brushes.Black, 660, 690) 
     e.Graphics.DrawString(underline.Text, labelFont, Brushes.Black, 643, 692) 
     e.Graphics.DrawString(grade12.Text, textFont, Brushes.Black, 660, 715) 
     e.Graphics.DrawString(grade13.Text, textFont, Brushes.Black, 660, 740) 
     e.Graphics.DrawString(grade14.Text, textFont, Brushes.Black, 660, 765) 
     e.Graphics.DrawString(grade15.Text, textFont, Brushes.Black, 660, 790) 
     e.Graphics.DrawString(grade16.Text, textFont, Brushes.Black, 660, 815) 
     e.Graphics.DrawString(grade17.Text, textFont, Brushes.Black, 660, 840) 
     e.Graphics.DrawString(grade18.Text, textFont, Brushes.Black, 660, 865) 
     e.Graphics.DrawString(grade19.Text, textFont, Brushes.Black, 660, 890) 
     e.HasMorePages = True 

    Case 2 

     e.Graphics.DrawString(grade20.Text, textFont, Brushes.Black, 0, 400) 
     e.HasMorePages = False 

    End Select 

    mPageNumber += 1 

End Sub 
+0

嗨joel謝謝你的回答,但我有一個忙,你能告訴我一個例子,使用我的代碼?謝謝你 – jane

+0

我加了一些代碼。 –

+0

謝謝你!我非常感謝你的幫助:) – jane