Stoffel85 Posted March 15, 2006 Posted March 15, 2006 (edited) Hi, I found a nice tutorial about printing multiple pages in VB.NET ( http://www.startvbdotnet.com/controls/printdialog.aspx ). But I can't figure it out. ... e.Graphics.MeasureString(Mid(RichTextBox1.Text, intCurrentChar + 1), font,_ New SizeF(PrintAreaWidth, PrintAreaHeight), fmt, intCharsFitted, intLinesFilled) ' calling MeasureString to determine the number of characters that will fit in ' the printing area rectangle e.Graphics.DrawString(Mid(RichTextBox1.Text, intCurrentChar + 1), font,_ Brushes.Black, rectPrintingArea, fmt) ' print the text to the page intCurrentChar += intCharsFitted 'advancing the current char to the last char printed on this page If intCurrentChar < RichTextBox1.Text.Length Then e.HasMorePages = True 'HasMorePages tells the printing module whether another PrintPage event should be fired Else e.HasMorePages = False intCurrentChar = 0 End If I have different strings that need to be printed. So do I need to do that MeasureString for every string I have? And another thing, I would like to check if a string fits on the page, if not print it on the other page, don't interupt it like in this example Is there also a way to count how many pages I would have because I would like to have an header and footer on every page and in the footer current page / total pages Is there another way to do this? (easier?) Thanks in advance Edited March 15, 2006 by Stoffel85 Quote
Stoffel85 Posted March 16, 2006 Author Posted March 16, 2006 I've managed to get my printing in order (for only 1 page) From the moment I got more pages, it just keeps printing the first page. This is some code I use '... Dim xPos As Single = marginLeft Dim yPos As Single = marginTop + 110 Dim lineHight As Single = fTekst.GetHeight(e.Graphics) Dim recTemp As RectangleF e.Graphics.DrawString("Dataset values:", fVet, Brushes.Black, marginLeft + 450, yPos) For i As Integer = 0 To nDsCa.Tables("categorie").Rows.Count - 1 e.Graphics.DrawString(CStr(nDsCa.Tables("categorie").Rows(i).Item(2)), fTekst, Brushes.Black, xPos + 550, yPos) yPos += lineHight Next yPos = marginTop + 110 e.Graphics.DrawString("Some text:", fVet, Brushes.Black, xPos, yPos) recTemp = New RectangleF(xPos + 130, yPos, 300, 1000) e.Graphics.DrawString(txtBleh.Text, fTekst, Brushes.Black, recTemp) yPos += e.Graphics.MeasureString(txtBleh.Text, fTekst, 300).Height e.Graphics.DrawString("Some more text:", fVet, Brushes.Black, xPos, yPos) e.Graphics.DrawString(txtMore.Text, fTekst, Brushes.Black, xPos + 130, yPos) yPos += lineHight '... I use that RectangleF for long text, so the text won't be longer then the width of that RectangleF (else it would go to far (out of printing range)) The problem however is, that I cannot know how long it has to be, so I set a heigth of 1000. Now it just keeps printing the first page whenever the text is to long. It doesn't even stop at the marginBottom, the text just keeps going untill you can't see it anymore. Some other questions I still have: - Is there a possibility to print something like Page 1 / ... with ... the total amount of pages - I have a header and footer that needs to be printed on every page. How can I do that. 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.