|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
First Report in VB2005 - Print PreviewNeed i simple example on how print/preview data from a database. I already have some code but I am lost because the preview does not create multiple pages and only shows the first page and the printing goes over the margins of the page. My problem is that I cannot figure out how to control new page when page is getting full. Another problem is that I would like to have a common place to set headers and footers to be printed every time a new page is sent. I would like to have a little code sample even with just printing lines. This is part of the code that I am using with MySQL database just going thru some records: While datareader.Read() e.Graphics.DrawString(datareader("upc").ToString, sfont, Brushes.Black, lblpos(0) + 0.5, YPosition) e.Graphics.DrawString(datareader("description").ToString, sfont, Brushes.Black, lblpos(1) + 0.5, YPosition) e.Graphics.DrawString(datareader("onhand").ToString, sfont, Brushes.Black, lblpos(2) + 0.5, YPosition) e.Graphics.DrawString(datareader("min").ToString, sfont, Brushes.Black, lblpos(3) + 0.5, YPosition) e.Graphics.DrawString(datareader("cost").ToString, sfont, Brushes.Black, lblpos(4) + 0.5, YPosition) e.Graphics.DrawString(datareader("price").ToString, sfont, Brushes.Black, lblpos(5) + 0.5, YPosition) CountLine += 1 YPosition = TopMargin + (CountLine * myFont.GetHeight(e.Graphics)) Console.WriteLine(">>>" & YPosition) If CountLine = 20 Then e.HasMorePages = False CountLine = 1 Else e.HasMorePages = True End If End While datareader.Close() Some of the code has been omitted. Thanks, -hb Hector M Banda wrote:
Show quoteHide quote > I would like to have a little code sample even with just printing lines. When you set HasMorePages = True, all that does is tell the printing> > This is part of the code that I am using with MySQL database just going thru > some records: > > While datareader.Read() > > e.Graphics.DrawString(datareader("upc").ToString, sfont, Brushes.Black, > lblpos(0) + 0.5, YPosition) > > CountLine += 1 > > YPosition = TopMargin + (CountLine * myFont.GetHeight(e.Graphics)) > > Console.WriteLine(">>>" & YPosition) > > If CountLine = 20 Then > > e.HasMorePages = False > > CountLine = 1 > > Else > > e.HasMorePages = True > > End If > > End While > > datareader.Close() > > Some of the code has been omitted. engine to call the print page event again. Normallty, when you set HasMorePages to true, you should exit the method. You need to keep track of where you are in the datareader so that when the PrintPage event is fired again, you pick up printing from that point. The DataReader should be created *outside* of the PrintPage method. When you reach the end of the page you are currently drawing on, if you still have more to print, you should set HasMorePages to true and then exit the PrintPage event. It will get fired again and you can pick up where you left off.
Unicode conversion
Net.WebRequest - Close Connection Resource and Time consuming stuff Virtual desktop makes .NET modal dialog panels disappear looking for tree/outline control that allows in-place editing AND will expand as I type Please explain the difference between close, dispose, = nothing on sqlClient. Returning an array from a function? Visual Studio beginner questions MAking a bound form from a query GDI Handle leak when adding a simple Textbox |
|||||||||||||||||||||||