Hello,
I'm trying to write a PrintDocument class that mimics the behavior of the System.Drawing.Printing.PrintDocument class on the full framework. I'm able to successfully create a Device Context to a printer and determine that it's resolution is 300dpi. I populate the "Graphics" member of the PrintPageEventArgs class by calling Graphics.FromHdc(hPrinterDC) where hPrinterDC is an IntPtr to the Printer DC. The resolution of the returned Graphics object is 96dpi, which happens to be the resolution of my display. Is it possible to get a Graphics object with the same resolution as the printer Everything I draw using the Graphics object is roughly 1/3 of the size it should be when printed. I've tried creating a Graphics object from a memory DC then copying and stretching its Bitmap to the printer DC, but this gives unacceptable results, especially when printing text.
Thanks

Graphics.FromHdc doesn't match resolution of Device Context
RajivB
This is a bug in NET CF. Graphics.FromHdc(hdc) really does wrap the given hdc with a managed object so you can use the Graphics object to print. However, Graphics.DpiX and Graphics.DpiY return cached values obtained from the screen device context, so you can't use them to scale objects in the printer dc.
You can work around this by p/invoking to the GetDeviceCaps API to get the correct values for the printer dc like this:
private Size GetResolutionFromDC(IntPtr hdc){
Size size = new Size();
size.X = GetDeviceCaps(hdc, DeviceCapabilities.LogicalPixelsX);
size.Y = GetDeviceCaps(hdc, DeviceCapabilities.LogicalPixelsY);
return size;
}
HTH
Dan