DPI/Large Fonts issues

J

James Hancock

There are a couple of things in the framework that don't handle nicely with
DPI changes (well lots of things but two that I have noticed)

#1 Background graphics on forms tile in large fonts instead of drawing the
graphic larger.
#2 All of the sizing functions are off when looking at graphics. I.e. a 24
pixel graphic is no longer 24 pixels in relation to the newly sized window
for large fonts. Hence if you size yoru control based on the size of a
graphic, the control is VERY small and looks out of place.
#3 Graphics all draw smaller instead of resizing along with everything else
the way they should.

Ok, so that's not such a big deal if we can work around these by getting the
DPI that windows is running in (the screen is running in) but the only
function I can find on this is the DPI of the graphics object, which of
course doesn't cut it. Any ideas on how to get the DPI of windows through
the .net framework so that I can do some math?

Thanks,
James Hancock
 
Y

Ying-Shen Yu[MSFT]

Hi James,
Thanks for your post!
you may get the Information by the Windows API EnumDisplaySettings by
PInvoke.
Here is the PInvoke definition
<code>
[DllImport("user32.dll")]
public extern static bool EnumDisplaySettings(string DeviceName,
int ModeNum, ref DEVMODE devMode);

[StructLayout(LayoutKind.Sequential)]
public struct DEVMODE{
[MarshalAs(UnmanagedType.ByValTStr,SizeConst:= CCHDEVICENAME)]
public string dmDeviceName;
public int dmSpecVersion;
public int dmDriverVersion;
public int dmSize;
public int dmDriverExtra;
public int dmFields;
public int dmOrientation;
public int dmPaperSize;
public int dmPaperLength;
public int dmPaperWidth;
public int dmScale;
public int dmCopies;
public int dmDefaultSource;
public int dmPrintQuality;
public int dmColor;
public int dmDuplex;
public int dmYResolution;
public int dmTTOption;
public int dmCollate;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst:= CCHFORMNAME)]
public string dmFormName;
public int dmUnusedPadding;
public int dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
}
</code>
For how to use EnumDisplaySettings you may refer to the following Link:
<EnumDisplaySettings>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons
_84oj.asp

Does this answer your question?


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
 

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