PrintDocument and Resolution

S

Steve

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
 
S

Steve

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.PrinterResolution.X = 300;
document.PrinterSettings.DefaultPageSettings.PrinterResolution.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
 
R

Rob Banfield

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top