From: Zach on


"Peter Duniho" <NpOeStPeAdM(a)NnOwSlPiAnMk.com> wrote in message
news:z8adncsDnsxI1ovRnZ2dnUVZ_uudnZ2d(a)posted.palinacquisition...
> Zach wrote:
>> Pete, how about this solution? [...]
>
---------------
". . . If the idea of maintaining the most-recently-read line
from the StreamReader seems too hard to understand . . ."

Pete,
My cranium can manage that,
even at 73 :) Yes my frend.

---------------

private void document_PrintPage(object sender, PrintPageEventArgs
ev)
{
float linesPerPage = 0;
float yPos = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;
int count = 0;
string query = null;
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics);
while (count < linesPerPage && ((line =
streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count *
printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
sr.ReadLine( );
count++;
}
if (line != null && (sr.ReadLine( ) != null))
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}



From: Zach on


"Zach" <xx(a)yy.zz> wrote in message
news:esfFTM$CLHA.5784(a)TK2MSFTNGP05.phx.gbl...
>
>
> "Peter Duniho" <NpOeStPeAdM(a)NnOwSlPiAnMk.com> wrote in message
> news:z8adncsDnsxI1ovRnZ2dnUVZ_uudnZ2d(a)posted.palinacquisition...


}
if (sr.ReadLine( ) != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}

One condition is enough of course. OhOh.
Sorry Pete.

Zach.

From: Zach on

Pete, it would appeear, on the bais of trials, that your stemenet is
incorrect.

if(!streamToPrint.EnfOfStream)
ev. HasMmorePages = true
etc . . . . .

Does stop a blank page form being prined. And no lines are lost either.

From: Peter Duniho on
Zach wrote:
>
> Pete, it would appeear, on the bais of trials, that your stemenet is
> incorrect.
>
> if(!streamToPrint.EnfOfStream)
> ev. HasMmorePages = true
> etc . . . . .
>
> Does stop a blank page form being prined. And no lines are lost either.

As I said, the bugs manifest themselves only with very specific input.
You can't just test the code with any text file you happen to have lying
around. It will depend on the combination of the file contents, the
font you're using, and the paper size.

As for your previous code snippets, I couldn't even find a declaration
for "sr", so I don't know what the calls to "sr.ReadLine()" are supposed
to accomplish. Hopefully, "sr" is not the same StreamReader that
"streamToPrint" refers to.

I meant no offense with my comment about one approach to fixing the code
being "too hard to understand" as compared to other approaches. The
simple fact is that different people have better or worse affinities to
different kinds of algorithmic approaches. We don't all think about
things the same way, and what makes for the easiest-to-write,
easiest-to-maintain code for one person is not always the same for
someone else.

Pete
From: Zach on
Pete,

> Hopefully, "sr" is not the same StreamReader that "streamToPrint" refers
> to.

* * * * * * No of course not. But I thought the solution, although
effective, was clumsy.
* * * * * * I have a print class in a number of my applications and wanted
to create a "standard" print class
* * * * * * to use when required, which is as perfect as I can get it.

> I meant no offense with my comment about one approach to fixing the code
> being "too hard to understand"

* * * * * * Thank you Pete, for your above remark. I much appreciate a
gentleman.

> As I said, the bugs manifest themselves only with very specific input. You
> can't just test the code with any text file you happen to have lying
> around. It will depend on the combination of the file contents, the font
> you're using, and the paper size.

I created a test file (so I did not use any old file, because that wouldn't
have been useful, given that the number of lines on the page is critical to
the bug appearing, so I changed the font size so as to vary the test
conditions, followed by retesting. That didn't bring any bugs to the fore.
Here in Holland (where I live and deveop) only A4 is used, in the context of
my administrative applications, not like in Anglo Saxon countries, with full
scap, etc.

If problems should still transpire, I will reinstate opening the file twice
and ascertaining if there is a line left to print for the "hasMorePages" to
potentially fire.

Zach