By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,859 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

Determine if Preview or Print() in OnPagePrint Event?

P: n/a
I have writting an application that prints fine, but I have to do a
TranslateTransform on the graphics in the OnPagePrint event to get place
output at exact X,Y (the application prints checks and must be placed
accurately).

However, when I do a print preview if I do the same translateTransform part
of the graphics is often just off the edge of the preview. Is there a way
to determine inside the OnPagePrint event if it's just a preview or the real
print function? I want to supress the TranslateTransform() if it's only a
preview.

I know I could rig something up with a global bool and set it when I do the
printPreviewDialog but I print in a seperate thread so it could be ugly and
less than perfect. This also wouldn't take into account if they clicked the
print button from within the preview window. Is there a more elegant way?

The relevant code is as follows:
private void docCheck_PrintPage(object sender, PrintPageEventArgs e)

{

//Shift the final graphics based on the printer offsets

//each "mark" from calibration sheet entered in numX & numY are equal to
3/100"

float xInchOffset = (float) xOffset *3 /100;

float yInchOffset = (float) yOffset *3 /100;

//HERE IS WHERE I WANT TO DO THE "if (!PrintPreview)" CODE TO SKIP THE NEXT
LINE

e.Graphics.TranslateTransform((float)xOffset *3,(float)yOffset *3);
Thanks,
Craig
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Craig,

I don't think there is a way to directly do this, but I think that you
might be able to perform some workarounds.

My first guess would be to get the graphics instance, and then get the
HDC for that graphics instance. Once you have that, you would pass it to
the GetDeviceCaps API function through the P/Invoke layer. I would try to
get the value for the TECHNOLOGY capability, and see if that returns a
printer (as opposed to a display).

If that doesn't work, I would check the PrintPageEventArgs passed to
you, specifically, the PageBounds and the PageSettings properties to see if
there is a noticable discrepancy.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Craig Scheets" <no****@nothanks.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
I have writting an application that prints fine, but I have to do a
TranslateTransform on the graphics in the OnPagePrint event to get place
output at exact X,Y (the application prints checks and must be placed
accurately).

However, when I do a print preview if I do the same translateTransform
part of the graphics is often just off the edge of the preview. Is there
a way to determine inside the OnPagePrint event if it's just a preview or
the real print function? I want to supress the TranslateTransform() if
it's only a preview.

I know I could rig something up with a global bool and set it when I do
the printPreviewDialog but I print in a seperate thread so it could be
ugly and less than perfect. This also wouldn't take into account if they
clicked the print button from within the preview window. Is there a more
elegant way?

The relevant code is as follows:
private void docCheck_PrintPage(object sender, PrintPageEventArgs e)

{

//Shift the final graphics based on the printer offsets

//each "mark" from calibration sheet entered in numX & numY are equal to
3/100"

float xInchOffset = (float) xOffset *3 /100;

float yInchOffset = (float) yOffset *3 /100;

//HERE IS WHERE I WANT TO DO THE "if (!PrintPreview)" CODE TO SKIP THE
NEXT LINE

e.Graphics.TranslateTransform((float)xOffset *3,(float)yOffset *3);
Thanks,
Craig

Nov 17 '05 #2

P: n/a
I didn't think about GetDeviceCaps, good thought... I'll see what's there.

Normally I think you'd be right about the PrintPageEventArgs too, but there
aren't any discrepancies in PageBounds because we're using ThinPrint on our
servers where this will run which is a virtual print driver. It always
returns 850x1100 for paper size, margins, pagebounds, etc on Letter Size
because it's more/less a PDF print driver with a virtual 100% printable
area. Oh Well :(

Thanks!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uE****************@tk2msftngp13.phx.gbl...
Craig,

I don't think there is a way to directly do this, but I think that you
might be able to perform some workarounds.

My first guess would be to get the graphics instance, and then get the
HDC for that graphics instance. Once you have that, you would pass it to
the GetDeviceCaps API function through the P/Invoke layer. I would try to
get the value for the TECHNOLOGY capability, and see if that returns a
printer (as opposed to a display).

If that doesn't work, I would check the PrintPageEventArgs passed to
you, specifically, the PageBounds and the PageSettings properties to see
if there is a noticable discrepancy.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Craig Scheets" <no****@nothanks.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
I have writting an application that prints fine, but I have to do a
TranslateTransform on the graphics in the OnPagePrint event to get place
output at exact X,Y (the application prints checks and must be placed
accurately).

However, when I do a print preview if I do the same translateTransform
part of the graphics is often just off the edge of the preview. Is there
a way to determine inside the OnPagePrint event if it's just a preview or
the real print function? I want to supress the TranslateTransform() if
it's only a preview.

I know I could rig something up with a global bool and set it when I do
the printPreviewDialog but I print in a seperate thread so it could be
ugly and less than perfect. This also wouldn't take into account if they
clicked the print button from within the preview window. Is there a more
elegant way?

The relevant code is as follows:
private void docCheck_PrintPage(object sender, PrintPageEventArgs e)

{

//Shift the final graphics based on the printer offsets

//each "mark" from calibration sheet entered in numX & numY are equal to
3/100"

float xInchOffset = (float) xOffset *3 /100;

float yInchOffset = (float) yOffset *3 /100;

//HERE IS WHERE I WANT TO DO THE "if (!PrintPreview)" CODE TO SKIP THE
NEXT LINE

e.Graphics.TranslateTransform((float)xOffset *3,(float)yOffset *3);
Thanks,
Craig


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.