473,398 Members | 2,380 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,398 software developers and data experts.

PrintSettings2

VR
Also,

I noticed that PageBounds and PageMargins rectangles are
not properly representing the page size (or it could be
the printer). The code below draws a rectangle on the
screen which isn't really centered, but rather shifted to
the right of the page:

private void OnPrintPage
(
object sender,
PrintPageEventArgs e) float fTop
)
{
float x = e.MarginBounds.Left;
float y = e.MarginBounds.Top;
float height = e.MarginBounds.Height;
float width = e.MarginBounds.Width;

Pen oPen3 = new Pen(Brushes.Black, 2.0F);
e.Graphics.DrawRectangle(oPen3, x, y, width, height);

e.HasMorePages = false;
}
Also, if I were to do the same with PageBounds rectangle,
should I be able to see it on the page, or should it be
drawn right at the very edge of the page?

When I look at PageBounds in debugger, I see left and top
set to 0 and width and height are 850 and 1100. I assumed
that a unit represents 1/100 of an inch, and therefore,
the rectangle should be right at the edge of the page --
probably shouldn't even come out.

But it does come out, and top left corner of the rectangle
is offset by about a 1/6 inch from top and left sides of
the page... The right and the bottom of the rectangle
don't even appear on the page.

So, I kept printing rectangles until they started
appearing in full on the page and it seems that it I have
to offset the right and the bottom sides of rectangle by
about 30-35 units from the right and the bottom (3/10
inch?).

Does anybody have a clue what I am talking about? (I jsut
re-read what I came up with and I barely understand
myself:))

Thanks for any suggestions.

VR
Nov 15 '05 #1
2 1075
To start with, the box not being at the edge of the page, is expected. From
the property "OriginAtMargins" of the PrintDocument class, it is evident
that the origin of the graphics object will either be "located just inside
the user-specified margins or at the top-left corner of the printable area
of the page". Take note - this is printable area of the page, which is
different for every printer (new "borderless" inkjets may very well be at
the very edge of the page, most laserjets need about a half-inch or so at
top & bottom).

http://msdn.microsoft.com/library/de...rginstopic.asp

Trying to center something on the page becomes somewhat of a guessing game,
if I recall. You have to assume that the printable area of the page is
centered within the actual page (which may be the case left to right, but
often is not the case top to bottom). MS seems to have not provided any way
to get to this piece of the puzzle. Petzold's book C# Windows Programming
has a really thorough description of the problem. I don't own the book (I
basically read the important chapters while sitting at a Borders book store)
and, unfortunately, don't remember if there is a good work-around, or what
it is.
http://www.microsoft.com/mspress/books/5188.asp

I believe there are basically two chapters of concern (whether or not it's
worth buying the book for those two chapters depends on how desperate you
are!):
Pages and transforms
Printing

I decided it wasn't something I needed correct for my documents, so I
stopped researching this. Now, as I think about this, I am getting more
confused than ever, so I'll just refer you to either Petzold's book (which
will at least restore some sanity, even if it doesn't give you your full
solution) and the aid of other ng'ers.

Good luck!

--
Mike Mayer
http://www.mag37.com/csharp/
mi**@mag37.com
"VR" <Vi***************@gat.com> wrote in message
news:06****************************@phx.gbl...
Also,

I noticed that PageBounds and PageMargins rectangles are
not properly representing the page size (or it could be
the printer). The code below draws a rectangle on the
screen which isn't really centered, but rather shifted to
the right of the page:

private void OnPrintPage
(
object sender,
PrintPageEventArgs e) float fTop
)
{
float x = e.MarginBounds.Left;
float y = e.MarginBounds.Top;
float height = e.MarginBounds.Height;
float width = e.MarginBounds.Width;

Pen oPen3 = new Pen(Brushes.Black, 2.0F);
e.Graphics.DrawRectangle(oPen3, x, y, width, height);

e.HasMorePages = false;
}
Also, if I were to do the same with PageBounds rectangle,
should I be able to see it on the page, or should it be
drawn right at the very edge of the page?

When I look at PageBounds in debugger, I see left and top
set to 0 and width and height are 850 and 1100. I assumed
that a unit represents 1/100 of an inch, and therefore,
the rectangle should be right at the edge of the page --
probably shouldn't even come out.

But it does come out, and top left corner of the rectangle
is offset by about a 1/6 inch from top and left sides of
the page... The right and the bottom of the rectangle
don't even appear on the page.

So, I kept printing rectangles until they started
appearing in full on the page and it seems that it I have
to offset the right and the bottom sides of rectangle by
about 30-35 units from the right and the bottom (3/10
inch?).

Does anybody have a clue what I am talking about? (I jsut
re-read what I came up with and I barely understand
myself:))

Thanks for any suggestions.

VR

Nov 15 '05 #2
Michael/Victor,
The 'solution' on Framework 1.0 is to use PInvoke on GetDeviceCaps and
retrieve the actual hard printer margins. I've got some code to do this and
it was also written up in MSDN Magazine several issues ago. Once you have
the printers hard margins just do a translate on the affected graphics
object by -left, -top and everything will then work the same as
PrintPreview. For added complications you may need to look at the overall
available print width and see if that fits your desired printed area. If it
is too small then you need to scale the graphics object appropriately. This
lets you print things on inkjet printers with large hard margins that
normally are output to laser systems. You may need to do this if your
printer's printable area is smaller than your margin bounds as well even on
Framework 1.1.

Ron Allen
"Michael Mayer" <mi**@mag37.com> wrote in message
news:Op**************@tk2msftngp13.phx.gbl...
To start with, the box not being at the edge of the page, is expected. From the property "OriginAtMargins" of the PrintDocument class, it is evident
that the origin of the graphics object will either be "located just inside
the user-specified margins or at the top-left corner of the printable area
of the page". Take note - this is printable area of the page, which is
different for every printer (new "borderless" inkjets may very well be at
the very edge of the page, most laserjets need about a half-inch or so at
top & bottom).

http://msdn.microsoft.com/library/de...rginstopic.asp
Trying to center something on the page becomes somewhat of a guessing game, if I recall. You have to assume that the printable area of the page is
centered within the actual page (which may be the case left to right, but
often is not the case top to bottom). MS seems to have not provided any way to get to this piece of the puzzle. Petzold's book C# Windows Programming
has a really thorough description of the problem. I don't own the book (I
basically read the important chapters while sitting at a Borders book store) and, unfortunately, don't remember if there is a good work-around, or what
it is.
http://www.microsoft.com/mspress/books/5188.asp

I believe there are basically two chapters of concern (whether or not it's
worth buying the book for those two chapters depends on how desperate you
are!):
Pages and transforms
Printing

I decided it wasn't something I needed correct for my documents, so I
stopped researching this. Now, as I think about this, I am getting more
confused than ever, so I'll just refer you to either Petzold's book (which
will at least restore some sanity, even if it doesn't give you your full
solution) and the aid of other ng'ers.

Good luck!

--
Mike Mayer
http://www.mag37.com/csharp/
mi**@mag37.com
"VR" <Vi***************@gat.com> wrote in message
news:06****************************@phx.gbl...
Also,

I noticed that PageBounds and PageMargins rectangles are
not properly representing the page size (or it could be
the printer). The code below draws a rectangle on the
screen which isn't really centered, but rather shifted to
the right of the page:

private void OnPrintPage
(
object sender,
PrintPageEventArgs e) float fTop
)
{
float x = e.MarginBounds.Left;
float y = e.MarginBounds.Top;
float height = e.MarginBounds.Height;
float width = e.MarginBounds.Width;

Pen oPen3 = new Pen(Brushes.Black, 2.0F);
e.Graphics.DrawRectangle(oPen3, x, y, width, height);

e.HasMorePages = false;
}
Also, if I were to do the same with PageBounds rectangle,
should I be able to see it on the page, or should it be
drawn right at the very edge of the page?

When I look at PageBounds in debugger, I see left and top
set to 0 and width and height are 850 and 1100. I assumed
that a unit represents 1/100 of an inch, and therefore,
the rectangle should be right at the edge of the page --
probably shouldn't even come out.

But it does come out, and top left corner of the rectangle
is offset by about a 1/6 inch from top and left sides of
the page... The right and the bottom of the rectangle
don't even appear on the page.

So, I kept printing rectangles until they started
appearing in full on the page and it seems that it I have
to offset the right and the bottom sides of rectangle by
about 30-35 units from the right and the bottom (3/10
inch?).

Does anybody have a clue what I am talking about? (I jsut
re-read what I came up with and I barely understand
myself:))

Thanks for any suggestions.

VR


Nov 15 '05 #3

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

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.