473,320 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to print graphic object via PrintDocument object?

I am still new on printdocument object. I have a problem
try to print graphic object. I have one graphics object.
How to print it? I try to print it in PrintPage event
using this syntax
e.Graphics = grhObj
by grhObj is graphics object that already has string, line
or other image in it. It is very difficult to recreate
this object in PrintPage event.

Nov 20 '05 #1
1 6179
Krich,
It is very difficult to recreate
this object in PrintPage event. IMHO its not as difficult as you may think!

Think of the Graphics object as a write once object. Unless you use
Graphics.FromImage to draw on a bitmap, what you draw is lost.

Also the resolution of most printers is far greater then your screen, if you
physically printed the bits from the screen you would loose resolution.

The code you use to draw on the screen should be the exact same code you use
to print on a page.

What I normally do is have the Control.Paint event call the same subroutine
that the PrintDocument.PrintPage event calls.

Private Sub Control_Paint(...) Handles ...Paint
Initialize(e.Graphics)
DrawObject(e.Graphics)
End Sub

Private Sub PrintDocument_PrintPage(...) Handles ...PrintPage
Initialize(e.Graphics)
DrawObject(e.Graphics)
End Sub

NOTE: Most of the initialization above is shared such as PageUnit,
PageScale, & zoom factor, so I call a common routine... I may need to
initialize a Graphics object without actually drawing so this is a
standalone routine.

Private Sub Initialize(ByVal gr As Graphics)
gr.PageUnit = GraphicsUnit.Millimeter
gr.PageScale = 1 ' My project uses Millimeters for the drawing
units.
gr.ScaleTransform(m_zoom, m_zoom)
End Sub

Then the DrawObject method will have all the logic to draw the object

Private Sub DrawObject(ByVal gr As Graphics)
gr.DrawString(...)
gr.DrawLine(...)
gr.DrawImage(...)
End Sub

Above DrawObject sub routine may actually be a method of a class, rather
then a member of the form itself.

Hope this helps
Jay
"Krich" <mr*****@hotmail.com> wrote in message
news:03****************************@phx.gbl... I am still new on printdocument object. I have a problem
try to print graphic object. I have one graphics object.
How to print it? I try to print it in PrintPage event
using this syntax
e.Graphics = grhObj
by grhObj is graphics object that already has string, line
or other image in it. It is very difficult to recreate
this object in PrintPage event.

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: lawrence | last post by:
How dangerous or stupid is it for an object to have a reference to the object which contains it? If I have a class called $controllerForAll which has an arrray of all the objects that exist, what...
3
by: Mika M | last post by:
Hi all! I have made an application for printing simple barcode labels using PrintDocument object, and it's working fine. Barcode printer that I use is attached to the computer, and this...
3
by: islay | last post by:
Hello, I'm trying to print more than one page using the PrintDocument object. I set "e.HasMorePages = True" after completeing the first page in the "PrintDocument1_PrintPage" subroutine, and...
7
by: pamela fluente | last post by:
hi, What is the cleanest and effective way to use the PrintDocument object to print directly to a pdf file "myfile.pdf" (with no prompt to the user: just print to file and make pdf) ? Does...
2
by: Ryan Liu | last post by:
In C#, what's is the difference between object vs Object, exception vs Exception? Thanks, ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. Ryan Liu Shanghai Fengpu Software Co. Ltd
5
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, I'm aware of the differences between string and String, but wondered what the differences were between object and Object? -- Regards, Phillip Johnson (MCPD Enterprise Developer)...
9
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I am just starting to write some code in C#. One time I accidently used "object" instead of "Object". The program didn't complain at all and worked fine. I am just wondering is there...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.