Font sizes are incorrect after WinForms scaling / Compact Framework
I'm confused as to how I can get my winforms to scale properly. When I design a form, in my case WVGA, horizontal orientation, it looks like the upper image below. On the device however, the text is scaled to be a lot larger. Setting a lower fontsize in the designer helps me getting it right, but this can't the the correct way of getting this done.
Designer vs device http://files.zzattack.org/images/cfwinformscaling_small.png.
What is the correct way of getting the fonts to appear equal in both designer and on my device? The AutoScaleMode.Font property isn't available on the Compact Framework, disabling autoscaling doesn't help either (same result as AutoScaleMode.Dpi), and setting the device's DPI in Visual Studio doesn't seem to help either.
Edit: I think I do sort of understand now. The form was originally designed for a 800x480 screen with dpi 96x96. Now, I'm trying to use this on a 800x480 screen with dpi 192x192. If I set AutoScaleMode to None, the form looks alright except for the fonts because none of the controls need to be moved or resized because the resolution matches. The DPI is different though, and that's why the fonts look bad. A 12pt font on 96x96 dpi looks a lot bigger on a 192x192 dpi screen. I don't understand this; I'd think it'd be the opposite way around.
It seems the "solution" would be to scale only the font sizes. Now I don't believe the winforms designer offers a nice, elegant solution to this, so I can just recurse through all controls in my form and set their fontsizes to halve the original.. This works, but it involves double the amount of fonts creations.
Also, odd font sizes get rounded down 开发者_开发知识库(on higher DPI!), so if the 96x96 form has a 7pt font which is quite readable, a 3pt font is selected (even if 3.5 is passed in the font constructor), which is a lot less readable. Not quite a nice solution. Does anyone know of a better one?
精彩评论