Link to home
Start Free TrialLog in
Avatar of Jerry_0001
Jerry_0001

asked on

Print problem

I want to print a page that has some text on it and a couple of datagrids.

For the moment I created some fonts, brushes and pens in the PrintDocument.PrintPage event handler.

I also been able to put the text on the paper also in this event handler.

My questions are as follows:

What's the best wat to show those datagrids (or tables) ?

What do I have to do when the page is full ? How can I start printing on the next page ?

Do I have to use DefaultPageSettings.Margins or can I go out of them ? Because these look a little too big. The space to put the text on is a bit too small.

Thanks!!!

Urgent help needed. :o)
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jerry_0001
Jerry_0001

ASKER

Thanks for the fast responses!!

But I'm still having some trouble with it.

The page layout should look something like this.

First page:

Image                Title

Some text

Datagrid 1

Text

Datagrid 2

Text Datagrid 3

...


At the end of each page there should be a footer (a line and below of that should be page 1 of N)

Starting page 2 there also should be a header (a name and a als a line)


Is it possible to give me such an exemple, since I'm totally stuck ???

Thanks!!!!
Urgent help needed please.

This app has to be finished and tested next monday...


Thanks!!!!
Is there nobody who can help me on this ???
There is not straight forward way to do what you are talking about.
You may have to go to to something like Crystal Reports.

Here is a link that gives you a few more ideas.

http://www.c-sharpcorner.com/Printing.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/printwinforms.asp
The image can be drawn in the PrintPage event with

e.Graphics.DrawImage(image, rect)

You will need to change fonts to draw your title, headers, footers, and/or text and datagrids.  That's demonstrated in the sample I posted above.  

You will have to calculate the positions where things are printed  yourself.  The only way to do this is to try it, and if you don't like what you have, modify it.  For the most part it's a matter of using the Graphics.MeasureString to calculate the height and width of  a string with a given font, then calculating where the next element will go based on that.  I use the

MyFontHeight = MyFont.GetHeight(ev.Graphics)

to calculate row height, since you want this to be a fixed number.

The lines can be drawn using the DrawLine function:

Dim pen As New Pen(Color.Black)
ev.Graphics.DrawLine(pen, point1, point2)

My advice is to get started yourself, and if you run into problems post back here with the code.
I will give it another try.

But what do I have to do I my first page is full ?

If I put everything in the printpage event handler, and the page is full (and I set HasMorePages = true), won't he start printing from the beginning again, instead of continuing where he stopped?

Ok, today I started to give it another try.

I have a first question though.

Is there a way to get the toal number of pages that will be printed ?

I would like to have a footer that has "Page 1 of 5" for example.

How can you do that ?
>If I put everything in the printpage event handler, and the page is full (and I set HasMorePages = true), won't he start printing from the beginning again, instead of continuing where he stopped?<

No because when you go to the print handler event, you track the number of rows you've printed in a module level variable.

>Is there a way to get the toal number of pages that will be printed ?

I would like to have a footer that has "Page 1 of 5" for example.

How can you do that ?<

Do a first run through to see how many rows/lines fit on the page.  Now use that number to calculate how many pages you will have.
Ok, I 've made a function for each line he has to print. When page is full he goes to another function that adds a page and then returns from where he came from.

Everything seems to work fine. It's a long and complicated solution but it does its job.

Thanks for the help.

Since you both helped me, I'll divide the points... Thanks!!
Glad you got it working, and thanks for the grade and the points.  :)