mikef74 Posted August 5, 2003 Posted August 5, 2003 I'm new to vb.net, and I'm trying to print from a form that was filled out. I've got it to work, but I'm not sure how to start a new page. This is the code I have so far. Any help would be appreciated. Thanks. Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage e.Graphics.DrawString(Title.Text, New Font("Arial", 18, FontStyle.Bold), Brushes.Black, 350, 100) e.Graphics.DrawString(Address1.Text, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 350, 130) If Address2.Text <> "" Then e.Graphics.DrawString(Address2.Text, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 350, 150) e.Graphics.DrawString(Address3.Text, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 350, 170) Else e.Graphics.DrawString(Address3.Text, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 350, 150) End If If CoverPic.Image Is Nothing Then Else e.Graphics.DrawImage(CoverPic.Image, 75, 300) End If End Sub Quote
bfellwock Posted August 5, 2003 Posted August 5, 2003 This was confusing to me at first also. In VB.NET the way you have it setup as far as using the System.Drawing.Printing.PrintDocument() class. I'm sure you have a top level variable dimmed like so: Private PrintDocument1 As New System.Drawing.Printing.PrintDocument() When you call PrintDocument1.Print() the sub gets called one time. If you want another page to print you must use your System.Drawing.Printing.PrintPageEventArgs. So, to print an additional page or several you would have this code in your sub: e.HasMorePages = True Setting the HasMorePages property to True tells the PrintDocument class to keep printing. To get it to stop printing you must set the property to false: e.HasMorePages = False So you have to put some counters and or flags maybe a Case or some If's in your sub to determine when and what to print. :) Quote
mikef74 Posted August 5, 2003 Author Posted August 5, 2003 I've played around with that a little bit, but I'm not sure that's what I need. I'm trying to specify when I want a new page to start. I got sections of the form printing on what will be the first (cover) page, now, I want the rest of the form to print on the second, third.... pages. Any suggestions on that? Quote
mikef74 Posted August 5, 2003 Author Posted August 5, 2003 in addition to what I just said.... this might help... Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage e.Graphics.DrawString(Title.Text, New Font("Arial", 18, FontStyle.Bold), Brushes.Black, 350, 100) e.Graphics.DrawString(Address1.Text, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 350, 130) If Address2.Text <> "" Then e.Graphics.DrawString(Address2.Text, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 350, 150) e.Graphics.DrawString(Address3.Text, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 350, 170) Else e.Graphics.DrawString(Address3.Text, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 350, 150) End If If CoverPic.Image Is Nothing Then Else e.Graphics.DrawImage(CoverPic.Image, 75, 300) End If ' START NEW PAGE HERE ' AND CONTINUE PRINTING End Sub Quote
bfellwock Posted August 5, 2003 Posted August 5, 2003 (edited) That is what I was talking about having to put like a flag in there to tell it what to print. It isn't like VB 4, 5, or 6. There is nothing to say ok I want a new page right here. See below: Private myFlag as Integer = 0 Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage If myFlag = 0 Then e.Graphics.DrawString(Title.Text, New Font("Arial", 18, FontStyle.Bold), Brushes.Black, 350, 100) e.Graphics.DrawString(Address1.Text, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 350, 130) If Address2.Text <> "" Then e.Graphics.DrawString(Address2.Text, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 350, 150) e.Graphics.DrawString(Address3.Text, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 350, 170) Else e.Graphics.DrawString(Address3.Text, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 350, 150) End If If CoverPic.Image Is Nothing Then Else e.Graphics.DrawImage(CoverPic.Image, 75, 300) End If myFlag += 1 e.HasMorePages = True ElseIf myFlag = 1 Then ' START NEW PAGE HERE ' AND CONTINUE PRINTING '*****Now here if you want to see when to go to the next page you can check the the margin bounds. There is a good example from aewarnick in C# that you can get some ideas from '*****http://www.xtremedotnettalk.com/showthread.php?s=&threadid=75229 e.HasMorePages = False End If End Sub Edited August 5, 2003 by bfellwock Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.