가장 쉬운 방법을 추가하는 헤더 및 글을 인쇄합니다.PrintDocument(.Net2.0)?
-
09-06-2019 - |
문제
What's 는 가장 쉬운 방법을 추가하는 헤더 및 글니다.Net PrintDocument 개체 중 하나,실용적으로 또는에서 디자인-time?
특히 하려고 해요 인쇄 제 3 자 그리드 제어(Infragistics GridEx v4.3)는 PrintDocument 개체고 그 자체입니다.
결과 페이지에 포함되는 그리드 및 그 내용-그러나 내가 좋아하는 헤더를 추가하거나 제목을 식별하는 인쇄된 보고서,그리고 아마도 바닥글을 표시하는 인쇄 할 때,그것 이상적으로 페이지 번호와 총 페이지입니다.
내가 사용하는 VB.Net 2.0.
당신의 도움을 주셔서 감사합니다!
해결책
Printdocument 개체 발생 printpage 이벤트에 대한 각각의 페이지를 인쇄할 수 있습니다.당신은 그릴 수 있는 텍스트/라인/등으로 인쇄 대기열을 사용하여 printpageeventargs 이벤트 매개변수:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx
희미한 그 WithEvents 전달할 때 그것은 그리드,그래서 당신은 처리할 수 있는 이벤트입니다.
다른 팁
다음 booji-boy's 응답,여기에 내가 와서(내가 나를 단순화에 대한 예 목적):
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim oDoc As New Printing.PrintDocument
oDoc.DefaultPageSettings.Landscape = True
AddHandler oDoc.PrintPage, AddressOf PrintPage
oDoc.DocumentName = "Printout"
InfragisticsWinGrid.PrintPreview(InfragisticsWinGrid.DisplayLayout, oDoc)
End If
End Sub
Private Sub PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
' Draw title
e.Graphics.DrawString("Report Title"), New Font("Arial", 16), Brushes.Black, 95, 70)
' Draw footer
e.Graphics.DrawImage(DirectCast(mResources.GetObject("footer_logo"), Drawing.Bitmap), 95, e.PageBounds.Height - 87)
Dim drawFont As New Font("Arial", 8.75)
e.Graphics.DrawString("Report Title", drawFont, Brushes.Gray, 190, e.PageBounds.Height - 90)
e.Graphics.DrawString("Printed", drawFont, Brushes.Gray, 190, e.PageBounds.Height - 76)
e.Graphics.DrawString("Printed By", drawFont, Brushes.Gray, 190, e.PageBounds.Height - 62)
' Draw some grid lines to add structure to the footer information
e.Graphics.DrawLine(Pens.Gray, 246, e.PageBounds.Height - 90, 246, e.PageBounds.Height - 48)
e.Graphics.DrawLine(Pens.Gray, 188, e.PageBounds.Height - 75, 550, e.PageBounds.Height - 75)
e.Graphics.DrawLine(Pens.Gray, 188, e.PageBounds.Height - 61, 550, e.PageBounds.Height - 61)
e.Graphics.DrawString("Report", drawFont, Brushes.Black, 250, e.PageBounds.Height - 90)
e.Graphics.DrawString(Date.Now.ToShortDateString & " " & Date.Now.ToShortTimeString, drawFont, Brushes.Black, 250, e.PageBounds.Height - 76)
e.Graphics.DrawString("Andrew", drawFont, Brushes.Black, 250, e.PageBounds.Height - 62)
End Sub
나는 값으로 재생의 e.PageBounds.Height - x
을 얻으려는 항목을 선니다.
다시 한번 감사 Booji 소년 에 대한 포인터를 얻기에 ReportPage.그래픽()는 정확히 무엇이었후:o)