Code:
Private Sub FormPrint_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
PrintHeader(e.Graphics)
End Sub
Private Sub PrintHeader(ByVal g As Graphics)
'Setup StringFormat to be used through the printing process
Dim CN_Format As New StringFormat
CN_Format.Trimming = StringTrimming.Word
CN_Format.FormatFlags = StringFormatFlags.NoWrap Or StringFormatFlags.LineLimit Or StringFormatFlags.NoClip
CN_Format.Alignment = HeaderAlignment
'Print CompanyName
If CompanyName.Length > 0 Then
Dim CN_Rect As RectangleF = New RectangleF(CType(LeftMargin, Single), CurrentY, CType(PageWidth, Single) - _
CType(RightMargin, Single) - CType(LeftMargin, Single), g.MeasureString(CompanyName, ReportFont).Height)
g.DrawString(CompanyName, ReportFont, New SolidBrush(Color.Black), CN_Rect, CN_Format)
CurrentY += g.MeasureString(CompanyName, ReportFont).Height
End If
If ReportTitle.Length > 0 Then
'Print the report title
Dim RT_Rect As RectangleF = New RectangleF(CType(LeftMargin, Single), CurrentY, CType(PageWidth, Single) - _
CType(RightMargin, Single) - CType(LeftMargin, Single), g.MeasureString(CompanyName, ReportFont).Height)
g.DrawString(ReportTitle, ReportFont, New SolidBrush(Color.Black), RT_Rect, CN_Format)
CurrentY += g.MeasureString(ReportTitle, ReportFont).Height
End If
If ShowReportDate = True Then
If ReportDate.ToString.Length = 0 Then ReportDate = Now.Date
Dim RptDate As String = String.Format("00/00/0000", ReportDate.ToString)
Dim DateRect As RectangleF = New RectangleF(CType(LeftMargin, Single), CurrentY, CType(PageWidth, Single) - _
CType(RightMargin, Single) - CType(LeftMargin, Single), g.MeasureString(RptDate, ReportFont).Height)
g.DrawString(RptDate, ReportFont, New SolidBrush(Color.Black), DateRect, CN_Format)
CurrentY += g.MeasureString(RptDate, ReportFont).Height
End If
If ShowPageNumber = True Then
Dim Page As String = "Page: " & PageNumber.ToString
Dim PageRect As RectangleF = New RectangleF(CType(LeftMargin, Single), CurrentY, CType(PageWidth, Single) - _
CType(RightMargin, Single) - CType(LeftMargin, Single), g.MeasureString(Page.ToString, ReportFont).Height)
g.DrawString(Page, ReportFont, New SolidBrush(Color.Black), PageRect, CN_Format)
CurrentY += g.MeasureString(Page, ReportFont).Height
End If
End Sub
However when I load the form, nothing at all shows up. What am I doing wrong??