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

Determine if Preview or Print() in OnPagePrint Event?

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
2 1901
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bob Darlington | last post by:
When I press F1 in print preview, I get the following error message for some (but not all) reports: 'The expression on Key Down you entered as the event property setting, produced the following...
3
by: Y. Gauthier | last post by:
Hi, I made a report with Access 2000 I show records, plus a total of some colums. I first had: totalC = col1 + col2 + col3 + col4 Then I changed it to: totalC = col1 + col2
0
by: Malcolm Cook | last post by:
I've discovered: Using "File > Print Preview" in a form's datasheet view with a server Filter crashes access after previewing... ....that is, unless ServerFilterByForm has been turned off...
1
by: sea | last post by:
I have Access 2002 and I am writing this application with a custom menu bar that has a print preview button -- the start up options hide the design window. The problem is that when an open form is...
2
by: Martin | last post by:
I have encountered a bug in print preview: In my program, data for printing is taken from arrays. When print preview is invoked or page is printed directly, it is ok, but when user prints from...
2
by: Craig Scheets | last post by:
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...
4
by: Gary | last post by:
Hello, I'm hoping someone can shed some light on why my report does not output the same results as shown in preview mode, which is to move the position of a check box based on a field value (see...
2
by: deepakfordotnet | last post by:
Hi, First of all let me confess that I could not get the solution to the same problem from an earlier post Printing :by Mr.Richard MSL (dated September 24th 2006) working. (Replied by Mr.Walter...
1
by: mailjaneen | last post by:
Hello, can someone help me. I want to display some fields on a report in print preview (i.e. instructions), that I don't want to print to the printer or export to file. I can't seem to find any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.