printing two pages

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi

i'm not to good at this stuff yet... but I hope some can help me
My problem is that I want to print two pages from my program
I tried to set the HasMorePages = true but it keeps posting the same stuff on the two pages, or sometimes the second page over the first page

my code looks like this

int i = 0

while ( i < 2

switch ( i )

case 0


WHAT I WANT TO PRINT ON PAGE ON



case 1


WHAT I WANT TO PRINT ON PAGE TW



e.HasMorePage = i < 1
i++
 
Hi,

Do you mean the code below is inside a printpage handler, if so, you
shouldn't use a while-construct. Store the i variable outside the
function. When you set hasmorepage = true then the event will be fired
again for the second page and so on... set it to false if you're at the last
page.

hth,
greetings


Joakim Olsson said:
hi.

i'm not to good at this stuff yet... but I hope some can help me.
My problem is that I want to print two pages from my program.
I tried to set the HasMorePages = true but it keeps posting the same stuff
on the two pages, or sometimes the second page over the first page.
 
thanks a million, I got it working from this

though there is a new problem.
when it comes to the second case, it prints the text on the first page.

How can I solve this

still same code as above.
 
Hi,

Joakim said:
thanks a million, I got it working from this.

though there is a new problem.
when it comes to the second case, it prints the text on the first page.

I'm not sure what you mean ? Do you mean both parts are on first page and
there isn't a second page printed ? Or it prints twice the same text ?

Anyway, I'm going to write the skeleton :

public class A
{
private int nPage;

public void Print ()
{
PrintDocument pd = new PrintDocument ();
nPage = 0;
pd.PrintPage += new PrintPageEventHandler(PrintPageHandler);
pd.Print();
}

private void PrintPageHandler(object sender, PrintPageEventArgs ev)
{
switch (nPage)
{
case 0:
// print page 1
break;
case 1:
// print page 2
break;
}
++nPage;
if ( nPage < 2) ev.HasMorePages = true;
else ev.HasMorePages = false;
}
}

Do you do it like this ?

hth,
greetings
 
thanks again.

it works from your code.
The problem was that it printed my second page on top of the first page. Everything was just on the same page.
I think it was because of the "while" statement.

thanks a million again. finally my first "hobby" program is finished.
 
Back
Top