static var in print function

SlyBoots

New member
Joined
Sep 28, 2009
Messages
4
Programming Experience
Beginner
Hello,
I've a little problem:

VB.NET:
If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
                AddHandler PrintDocument1.PrintPage, AddressOf PrintDocument_PrintPage      
                PrintDocument1.DocumentName = "---"
                PrintDocument1.Print()
End If

and the PrintDocument_PrintPage:

VB.NET:
e.Graphics.RenderingOrigin = New Point(e.MarginBounds.Left, e.MarginBounds.Top)
Dim Font As New Font("Arial", 10, FontStyle.Regular)
Dim CharHeight As Single = Font.GetHeight(e.Graphics)
Dim Y As Int16 = e.MarginBounds.Top
Static page As Integer = 0
...
if page = 0 Then
   printHeader(e)
end if
...
if e.HasMorePage Then
   page += 1
end if

Now, printing works fine... the first time. If I repeat printing, the printHeader is skipped: page <> 0, because it isn't re-initialized :mad:
Why the static vars aren't re-initialized when I start a new printing? How fix it?

Thanks
 
Back
Top