473,397 Members | 1,950 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,397 software developers and data experts.

PrintDocument and Resolution

I'm trying real hard to set the printer resolution for a PrintDocument. It
appears that the printer is already set to 300 x 300 dpi, which is JUST what
I want.
But the Margins and PrintableArea properties of the PageSettings in the
Print handler are reporting values that indicate 100 dpi, for example it
reports PaperSize as 850, 1100 (8.5" x 11")

I'm passing these Rectangle properties into a method that is drawing
thinking it's working on a 300 DPI Image, so if it gets a Graphics context
that is 100dpi, everything is out of bounds.

What I don't understand is why the MSDN docs say you can set the printer
resolution with the PrinterResolution property of the pageSettings class,
but there is no Set accessor for the X and Y Properties.

I'm trying not to get frustrated, but this just seems so mixed up.

Do I need to set the resolution on the PrintDocument I've created? Can
someone please give me some tips on how to draw to a printer (is that what
you call it?) at 300 DPI?

Thanks for reading,
Steve
Jun 22 '06 #1
2 28393
Correction: you can set it, but the intellisense set "Gets" and I just took
it literally. Apologies.
Here is the code I have:
private void linkLabel_asd_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e)
{
PrintDocument document = new PrintDocument();

document.PrinterSettings.DefaultPageSettings.Print erResolution.X = 300;
document.PrinterSettings.DefaultPageSettings.Print erResolution.Y = 300;
document.PrintPage += new PrintPageEventHandler(document_PrintPage);
printPreviewDialog1.Document = document;
printPreviewDialog1.ShowDialog();
}

private void document_PrintPage(object sender, PrintPageEventArgs e)
{
e.PageSettings.PrinterResolution.X = 300;
e.PageSettings.PrinterResolution.Y = 300;
e.PageSettings.PrinterSettings.DefaultPageSettings .PrinterResolution.X =
300;
BuildSNLabelGenerator gen = new BuildSNLabelGenerator();
gen.GenerateLabelSheets(e.Graphics, new SizeF(1.78F, 0.50F),
e.MarginBounds, true);
// Image image = gen.GenerateLabelSheets(true);
// e.Graphics.DrawImage(image, new Point(0, 0));
}
e.PageBounds is still returning 850 x 1100

Any ideas?
I have tried setting the PrinterDocument resolution to 300x300 and tried the
"Steve" <sk**@skle.com> wrote in message
news:Oz**************@TK2MSFTNGP04.phx.gbl...
I'm trying real hard to set the printer resolution for a PrintDocument.
It appears that the printer is already set to 300 x 300 dpi, which is JUST
what I want.
But the Margins and PrintableArea properties of the PageSettings in the
Print handler are reporting values that indicate 100 dpi, for example it
reports PaperSize as 850, 1100 (8.5" x 11")

I'm passing these Rectangle properties into a method that is drawing
thinking it's working on a 300 DPI Image, so if it gets a Graphics context
that is 100dpi, everything is out of bounds.

What I don't understand is why the MSDN docs say you can set the printer
resolution with the PrinterResolution property of the pageSettings class,
but there is no Set accessor for the X and Y Properties.

I'm trying not to get frustrated, but this just seems so mixed up.

Do I need to set the resolution on the PrintDocument I've created? Can
someone please give me some tips on how to draw to a printer (is that what
you call it?) at 300 DPI?

Thanks for reading,
Steve

Jun 23 '06 #2
I've always avoided trying to set the printer's Margins and
PrintableArea, preferring instead to recognize where the printer's hard
margins are, and setting up my own reference point somewhere within
these hard margins. Then, all printing and positioning is done with
respect to this reference point. Remember that you can print ANYWHERE
you like in the infinite 2D printer surface; but only those parts of
your output which lie within the printer's hard margins will actually
appear on the paper.
But the Margins and PrintableArea properties of the PageSettings in the
Print handler are reporting values that indicate 100 dpi, for example it
reports PaperSize as 850, 1100 (8.5" x 11")

actually, these properties are independent of the printer resolution,
and are always returned in units of one-hundredth inch. I personally
prefer to set up my PrintDocument to work exclusively in millimeters,
so I read in the 1/100 inch values and convert to mm.

I think you will need the GetHdevMode() and SetHdevMode() methods of
the PrinterSettings class if you want to actually set the printer
resolution to something other than the printer's standard resolution
(and a lot more besides!) - these methods use a handle to a DEVMODE
structure which corresponds to the printer settings. Look up the
DEVMODE structure in the Win32 SDK help, but for starters here's the
structure definition:

typedef struct _devicemode { // dvmd
BCHAR dmDeviceName[CCHDEVICENAME];
WORD dmSpecVersion;
WORD dmDriverVersion;
WORD dmSize;
WORD dmDriverExtra;
DWORD dmFields;
short dmOrientation;
short dmPaperSize;
short dmPaperLength;
short dmPaperWidth;
short dmScale;
short dmCopies;
short dmDefaultSource;
short dmPrintQuality;
short dmColor;
short dmDuplex;
short dmYResolution;

short dmTTOption;
short dmCollate;
BCHAR dmFormName[CCHFORMNAME];
WORD dmLogPixels;
DWORD dmBitsPerPel;
DWORD dmPelsWidth;
DWORD dmPelsHeight;
DWORD dmDisplayFlags;
DWORD dmDisplayFrequency;
#if(WINVER >= 0x0400)
DWORD dmICMMethod; // Windows 95 only
DWORD dmICMIntent; // Windows 95 only
DWORD dmMediaType; // Windows 95 only
DWORD dmDitherType; // Windows 95 only

DWORD dmReserved1; // Windows 95 only
DWORD dmReserved2; // Windows 95 only
#endif /* WINVER >= 0x0400 */
} DEVMODE;
HTH,
Rob
Steve wrote: Correction: you can set it, but the intellisense set "Gets" and I just took
it literally. Apologies.
Here is the code I have:
private void linkLabel_asd_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e)
{
PrintDocument document = new PrintDocument();

document.PrinterSettings.DefaultPageSettings.Print erResolution.X = 300;
document.PrinterSettings.DefaultPageSettings.Print erResolution.Y = 300;
document.PrintPage += new PrintPageEventHandler(document_PrintPage);
printPreviewDialog1.Document = document;
printPreviewDialog1.ShowDialog();
}

private void document_PrintPage(object sender, PrintPageEventArgs e)
{
e.PageSettings.PrinterResolution.X = 300;
e.PageSettings.PrinterResolution.Y = 300;
e.PageSettings.PrinterSettings.DefaultPageSettings .PrinterResolution.X =
300;
BuildSNLabelGenerator gen = new BuildSNLabelGenerator();
gen.GenerateLabelSheets(e.Graphics, new SizeF(1.78F, 0.50F),
e.MarginBounds, true);
// Image image = gen.GenerateLabelSheets(true);
// e.Graphics.DrawImage(image, new Point(0, 0));
}
e.PageBounds is still returning 850 x 1100

Any ideas?
I have tried setting the PrinterDocument resolution to 300x300 and tried the
"Steve" <sk**@skle.com> wrote in message
news:Oz**************@TK2MSFTNGP04.phx.gbl...
I'm trying real hard to set the printer resolution for a PrintDocument.
It appears that the printer is already set to 300 x 300 dpi, which is JUST
what I want.
But the Margins and PrintableArea properties of the PageSettings in the
Print handler are reporting values that indicate 100 dpi, for example it
reports PaperSize as 850, 1100 (8.5" x 11")

I'm passing these Rectangle properties into a method that is drawing
thinking it's working on a 300 DPI Image, so if it gets a Graphics context
that is 100dpi, everything is out of bounds.

What I don't understand is why the MSDN docs say you can set the printer
resolution with the PrinterResolution property of the pageSettings class,
but there is no Set accessor for the X and Y Properties.

I'm trying not to get frustrated, but this just seems so mixed up.

Do I need to set the resolution on the PrintDocument I've created? Can
someone please give me some tips on how to draw to a printer (is that what
you call it?) at 300 DPI?

Thanks for reading,
Steve


Jun 23 '06 #3

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

Similar topics

3
by: Palli Olafs | last post by:
Hi Is it possible to save the PrintDocument as file without using a printer?
1
by: Krich | last post by:
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...
2
by: Philippe | last post by:
I'm writing a vb.net application that prints jpeg pictires, and although I set the defaultpageSettings.printerResolution of my PrintDocument object to the maximum available printer resolution...
0
by: active | last post by:
Dim mPD As PrintDocument Dim mPrinternameSaved As PrintDocument Public WriteOnly Property PrintDocument() As PrintDocument Set(ByVal value As PrintDocument) mPD = value mPrinternameSaved = mPD...
1
by: Chris Dunaway | last post by:
When using PrintDocument to print something, if I check the PageBounds property of the PrintPageEventArgs object, it shows the rectangle to be 850 x 1100, or 100 dpi. But when I check the value of...
0
by: Fabio | last post by:
Hi all! I have some problems with the PrintDocument under Fw 1.1. I create a new document pd = new PrintDocument And it seems that the pd.PrinterSettings are the ones defined by the...
2
by: bp | last post by:
Hi, I try to use my own PreviewDialog with a PrinPreviewControl, to preview a document of type MyPrintDocument, and I want to implement the PrintRange functionnality (print some pages between 2...
1
by: kig25 | last post by:
Hello, When using the VB.NET PrintDocument class, I seem to be encountering an issue where the sub pd_PrintPage handles PrintDocument.PrintPage (upon continuing if HasMorePages = true) will...
6
by: Lloyd Dupont | last post by:
Before printing I create an instance of PrintDocument as Follow (beware, pseudo code) //============================== PrinterResolution pr = new PrinterResolution(); pr.X= 600; pr.Y= 600;...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.