Re: Simple printing and graphics



First of all, everything in the printed page is graphics, including text.

The PrintDocument class is what does the Printing. When you call the Print
method of the PrintDocument class, it prints. How you get your graphics into
it is by wiring up an event handler to the PrintDocument.Print event. This
event passes a System.Drawing.Printing.PrintPageEventArgs instance, which
contains, among other things, the Graphics object you need to draw to.

It's a bit more complex than that, however. The PrintDocument class also has
a PageSettings and PrinterSettings instance in it. These determine which
Printer to print to, any additional Printer settings, and page information
about the page to print to. This includes (very important) the Printable
Area of the page, and the Margins of the page. The Graphics instance passed
will be relative to the Printing area of the page, but may or may not
(optionally) include the margins.

The Print event of the PrintDocument is the place where you can do your
paging. The PrintPageEventArgs class has a member called "HasMorePages." If
you set this to true, the handler will be called again. Since the handler
does the drawing, it can draw as many pages as you wish, just by changing
what it draws with each event.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.


"Chris Dunaway" <dunawayc@xxxxxxxxx> wrote in message
news:1152123745.279038.280900@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
The method for printing documents in .Net can be confusing, especially
for newer users. I would like to create a way to simplify this
process. My idea would be implemented using a PrintDocument (much like
the current model), but my PrintDocument would have a Pages collection
such that each time you need to have an additional page, you would just
add another page to the collection and then use the page object for the
actual drawing etc. Finally, when you wanted to submit the document to
the printer, you would call the Print method. The following pseudo
code shows what I intend:

PrintDocument pd = new PrintDocument();

//Add the first page
Page p = pd.AddPage();

//Here, draw things, data, etc. to the page
p.DrawString(x, y, font, "string to be drawn");
p.DrawCircle(x, y, radius);

if (anotherpageneeded)
p = pd.AddPage();

//More drawing to the page here

//Finally, submit the document to the printer
pd.Print();


My question, is how to represent or "store" the pages graphics. Should
I create a Graphics object internally to the page object? Or should I
create a "pseudo" drawing language and use something like a hashtable
to store each drawing command. Can a Graphics object be created and
then somehow "copied" to a destination graphics object?

I'm just looking for a suggestion on how to persist in each page object
the necessary commands to render the page to the printer's graphics
object. I guess I'm wondering if a Graphics object can be created,
drawn to, and then copied or rendered onto another Graphics object?
And how do I create a Graphics object that is the same scale, etc. as
the one used by the printer?

Thanks for any suggestions,

Chris



.



Relevant Pages

  • Re: "object is currently in use elsewhere" - Im stumped
    ... I don't see a direct use of DC objects in your code, but the Graphics ... PrintDocument that is created each time the Print method is called. ... "Print(Image image, string documentName, string printerName) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: PictureBox to Print Page...
    ... > PrintDocument printDoc = new PrintDocument; ... > PrintPreviewDialog printPreviewDlg = new PrintPreviewDialog; ... > using (Graphics graphicsImage = Graphics.FromImage(imageForPrinting)) ... > new SolidBrush, labelLocation); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Multithreaded IntPtr Hdc problem - Common or obscure error?
    ... If you had a computer with mulitple screens and a separate graphics object ... > int usedHeight = rect.Height; ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Different ways for persistent graphics in VB.net
    ... you are saying that anything drawn on the graphics ... You don't draw ON a graphics object - you draw WITH a graphics object. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Different ways for persistent graphics in VB.net
    ... you are saying that anything drawn on the graphics ...  You do not draw on the graphics object. ... It is a tool to draw on the canvas to which it is associated. ...
    (microsoft.public.dotnet.languages.vb)

Loading