Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Printers and VisibleClipBounds ...

83 views
Skip to first unread message

Nicola Cisternino

unread,
Jul 3, 2002, 4:13:09 AM7/3/02
to
Hi all,

I'm using the "CreateMeasurementGraphics" method of
System.Drawing.Printing.PrinterSettings object to determine the printable
area BEFORE the report has starting.
Now, all work fine .... but if i change programmatically the papersize of
the PrinterSettings.DefaultPageSettings object , Bounds properties are
updated ..... VisibleClipBound none ! ...
Only if i change the default papersize of the printer using the Windows
Control Panel all work fine!

Ideas?

Thanks in advance.


This is the sample code:
================
Dim Prs As New System.Drawing.Printing.PrinterSettings()
Dim G As Graphics

With Prs.DefaultPageSettings
' I print the default Pagesize and VisibleClipBounds of default
printer ...
Console.WriteLine(.Bounds.Width.ToString + " " +
.Bounds.Height.ToString)
G = Prs.CreateMeasurementGraphics
Console.WriteLine(G.VisibleClipBounds.Width.ToString + " " +
G.VisibleClipBounds.Height.ToString)

' ... Now change programmatically the paper size
.PaperSize = New System.Drawing.Printing.PaperSize("custom",
300, 300)

' Bounds properties are updated ..... VisibleClipBound none !
...
Console.WriteLine(.Bounds.Width.ToString + " " +
.Bounds.Height.ToString)
G = Prs.CreateMeasurementGraphics
Console.WriteLine(G.VisibleClipBounds.Width.ToString + " " +
G.VisibleClipBounds.Height.ToString)
End With

================


Mike

unread,
Jul 3, 2002, 12:22:56 PM7/3/02
to
"Nicola Cisternino" <devel...@cointa.it> wrote in
news:OiFHclmICHA.2664@tkmsftngp08:

> Hi all,
>
> I'm using the "CreateMeasurementGraphics" method of
> System.Drawing.Printing.PrinterSettings object to determine the
> printable area BEFORE the report has starting.

Maybe I missed an earlier post, but why aren't you using MarginBounds?

> Now, all work fine .... but if i change programmatically the papersize
> of the PrinterSettings.DefaultPageSettings object , Bounds properties
> are updated ..... VisibleClipBound none ! ...
> Only if i change the default papersize of the printer using the
> Windows Control Panel all work fine!

Ok...if you don't mind starting from the beginning, what is it you're
trying to accomplish?

mike

Nicola Cisternino

unread,
Jul 4, 2002, 5:39:09 AM7/4/02
to
Hi Mike, and thanks for the reply

... I'm not using MarginBounds becouse our Report class (that perform some
font size valutation depending on printable area ....) not print directly on
the printer but it save all on a XML file.
During the night a "stupid" service program read all these (big) files (
...where are stored the printer name, the report details and other...) and
send them to the printers.
These are a sort of resident spool files that are also readable with a
Preview function ....
... Now ... when the final user of client application choose a printer and a
papersize, my program has need to know the exact printable area without use
the PrintDocument object .......(...and relative events as "PrintPage" ....)
Only the "batch" server program use the PrintDocument object ..... but the
decision step is located on the client ......

Then i can't use the PrintPageEventArgs classes .. :-(((

Some suggestion ?? ...

P.S.
=================
... .NET is really wonderful ......... but (... this is only my point of
view...) old VB6 Printer object, even if it had less functions, was very
more flexible.
In fact i think that "Push" object are better than "Pull" ......

Regards ...


"Mike" <mjea...@yahoo.com> ha scritto nel messaggio
news:Xns92407DF2D4CD7...@216.168.3.40...

Mike

unread,
Jul 4, 2002, 9:34:08 AM7/4/02
to
> ... Now ... when the final user of client application choose a printer
> and a papersize, my program has need to know the exact printable area
> without use the PrintDocument object .......(...and relative events as
> "PrintPage" ....) Only the "batch" server program use the
> PrintDocument object ..... but the decision step is located on the
> client ......

Well, on the client, why couldn't you create a PrintDocument object long
enough to grab the margins? You could then destroy the PrintDocument
object and pass the info to the function that writes the XML.

Does that sound reasonable?

mike

Nicola Cisternino

unread,
Jul 5, 2002, 5:02:37 AM7/5/02
to
"Mike" <mjea...@yahoo.com> ha scritto nel messaggio
news:Xns92416152517BB...@216.168.3.40...
===================================================

Ok, but to obtain the info (by PrintPageEventArgs) i must invoke the "Print"
method that starts the printer .... and i don't want any printer "movement"
....
The only way could be:
1) create a PrintDocument
2) choose the printer
3) choose the printer size
4) invoke the PrintDocument.Print method
5) get all info in the delegated PrintPage subroutine
6) use the "Cancel" property to avoid this useless printer queue
7) destroy the PrintDocument object

... i think that isn't an "elegant" solution ....

Another solution could be:
1) create PrinterSettings object
2) choose the printer
3) store the printable margins values (G.ClipBounds - G.VisibleClipBounds)
that with the default papersize are correct ...
4) apply these margins to any possible printer size

... i like more this .... :-))

If you believe that i have not understood your idea (with PrintDocument
object) please send me a small sample.

Regards.

Mike

unread,
Jul 5, 2002, 12:20:36 PM7/5/02
to
> ... i think that isn't an "elegant" solution ....
>
> Another solution could be:
> 1) create PrinterSettings object
> 2) choose the printer
> 3) store the printable margins values (G.ClipBounds -
> G.VisibleClipBounds) that with the default papersize are correct ...
> 4) apply these margins to any possible printer size
>
> ... i like more this .... :-))
>
> If you believe that i have not understood your idea (with
> PrintDocument object) please send me a small sample.

Yea...something like this, but I was thinking of

1) create a PrintDocument object
2) Choose the printer
3) Retrieve the PrintDocument.DefaultPageSettings.Margins

You should probably grab the printer hard margins as well (using
GetDeviceCaps) and take those into account.

mike

Nicola Cisternino

unread,
Jul 6, 2002, 4:28:56 AM7/6/02
to
>
> Yea...something like this, but I was thinking of
>
> 1) create a PrintDocument object
> 2) Choose the printer
> 3) Retrieve the PrintDocument.DefaultPageSettings.Margins
>
> You should probably grab the printer hard margins as well (using
> GetDeviceCaps) and take those into account.
>
> mike

Well ...
I have really need of hard margins ........ and VisibleClipBounds returns
them !!!
PageSettings.Margins are only logical margins (on my printer hard margins
are about 35 points ..... while PageSettings.Margins are statically set on
100 points ...)
Your idea to use GetDeviceCaps is really interesting !! it's an API call
that i not ever used.
Now to use it: VB6 has the hWnd property (in .net renamed "Handle") and the
hdc property.
Do you know how i can retrieve the hdc value of the printer ?? .... and of
a generic Form ???

Very Thanks!
Nicola.

Ron Allen

unread,
Jul 7, 2002, 1:20:36 PM7/7/02
to
Nicola,
VisibleClipBounds doesn't return the printers hard margins but does show
the total visible width/height of the printable area. While dividing the
difference between this and the page boundaries by two returns an
approximation of the hard margins, this measurement may be off by a fairly
large amount for printers with non-symmetric page margins as some inkjet
printers have.

If you create a 'dummy' PrintDocument OnPrintPage call you can get the
actual margins of the printer using PInvoke. Just have the dummy routine
immediately return after checking the hard margins of the printer (and set
HasMorePages to false). The PrintPageEvent args for this routine will
contain a Graphics from which you can obtain the hDC to the printer to make
the call. Make sure you relase the hDc after grabbing it though. This
hasn't caused any printer queue activity that causes a problem in my
applications.

Why not set margins, font sizes, and indents as you desire and then, in
the actual print call, compare your default margins/page width/height to the
actual device printable width/height and the set an overall scaling factor
for the page depending on the minimum scale of height/width. This works
well for me and thus doesn't require setting up different font sizes and
measurements based on the printer selected. For example using one of my
reports I have a left/top/bottom/right margin of 0.5" for letter sized paper
which creates a width of 7.5" and a height of 10.0". I retrieve the printer
'hard margins' and use those for offsets in my printing libraries and
compare the actual printer printable width/height to create a scale factor
for the x and y directions. If either of these scale factors is less than 1
I set the overall scaling mode for the Graphics to the minimum of the two
scales for the page. This makes the document printing independent of the
printer chosen at print time so my users can transfer (xml) documents by
e-mail and print them with the same results at any location.

Ron Allen

"Nicola Cisternino" <devel...@cointa.it> wrote in message
news:#HFJScMJCHA.668@tkmsftngp09...

Nicola Cisternino

unread,
Jul 8, 2002, 8:07:42 AM7/8/02
to
Hi Ron, and thanks for the reply !

"Ron Allen" <ron-...@starpower.net> ha scritto nel messaggio
news:eJh6AqdJCHA.2572@tkmsftngp08...


> Nicola,
> VisibleClipBounds doesn't return the printers hard margins but does
show
> the total visible width/height of the printable area. While dividing the
> difference between this and the page boundaries by two returns an
> approximation of the hard margins, this measurement may be off by a fairly
> large amount for printers with non-symmetric page margins as some inkjet
> printers have.


You are right ..... "GetDeviceCaps" is the better way ...


> If you create a 'dummy' PrintDocument OnPrintPage call you can get the
> actual margins of the printer using PInvoke. Just have the dummy routine
> immediately return after checking the hard margins of the printer (and set
> HasMorePages to false). The PrintPageEvent args for this routine will
> contain a Graphics from which you can obtain the hDC to the printer to
make
> the call. Make sure you relase the hDc after grabbing it though. This
> hasn't caused any printer queue activity that causes a problem in my
> applications.


How are you using the OnPrintPage method ??
...are you inheriting the original PrintDocument Class ??
Can you send me an example ??
The only way that i've found to retrieve the printer information has been
that to start a "virtual" print aborted in the PrintPage event .....


> Why not set margins, font sizes, and indents as you desire and then,
in
> the actual print call, compare your default margins/page width/height to
the
> actual device printable width/height and the set an overall scaling factor
> for the page depending on the minimum scale of height/width. This works
> well for me and thus doesn't require setting up different font sizes and
> measurements based on the printer selected. For example using one of my
> reports I have a left/top/bottom/right margin of 0.5" for letter sized
paper
> which creates a width of 7.5" and a height of 10.0". I retrieve the
printer
> 'hard margins' and use those for offsets in my printing libraries and
> compare the actual printer printable width/height to create a scale factor
> for the x and y directions. If either of these scale factors is less than
1
> I set the overall scaling mode for the Graphics to the minimum of the two
> scales for the page. This makes the document printing independent of the
> printer chosen at print time so my users can transfer (xml) documents by
> e-mail and print them with the same results at any location.
>
> Ron Allen

... Becouse in my reports i need to print a fixed number of columns by row
... then i set a font size that allows to format correctly these characters
.....
However your way to redraw the graphic page depending on the "client"
phisical paper size is very interesting. Thank you for idea. (... are you
using "ScaleTransform" ??? )

Very Thanks!
Nicola.


0 new messages