gpt4 book ai didi

.net - 将页眉和页脚添加到 Printing.PrintDocument (.Net 2.0) 的最简单方法?

转载 作者:行者123 更新时间:2023-12-04 23:11:39 25 4
gpt4 key购买 nike

将页眉和页脚添加到 .Net PrintDocument 对象的最简单方法是实用的还是在设计时?

具体来说,我正在尝试打印一个 3rd 方网格控件(Infragistics GridEx v4.3),它接受一个 PrintDocument 对象并将其自身绘制到其中。

结果页面只包含网格及其内容 - 但是我想添加一个标题或标题来标识打印的报告,可能还有一个页脚来显示谁打印了它,何时打印,最好是页码和总页数。

我正在使用 VB.Net 2.0。

谢谢你的帮助!

最佳答案

关注 booji-boy的答案,这是我想出的(出于示例目的,我已对其进行了简化):

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 Boy对于指针 - 获得 ReportPage.Graphics() 正是我所追求的 :o)

关于.net - 将页眉和页脚添加到 Printing.PrintDocument (.Net 2.0) 的最简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com