.Net Inconsistent Font rendering

徘徊边缘 提交于 2019-12-22 10:46:06

问题


I am creating an .Net 2.0 SP2 windows Forms Application. The form fonts looks fine in my machine, when i tried in another machine, it looks bigger. (This is not because of resolution difference, fonts are bigger relatively to other icons etc.)

I tried to debug the problem and found following code returns different sizes on different machine.

//inside a windows form
private void checkfont()
{
    var g = this.CreateGraphics();
    MessageBox.Show(g.MeasureString("Hello World", this.Font) + "," + this.Font);
}

I expect graphics.measurestring() to return same value for same arguments in different machines.

For font 'Verdana 8.25'

  • On Machine 1 "Hello World" measures 69.0px,14.7px
  • On Machine 2 "Hello World" measures 86.3px,18.4px

Why this difference ? because of this my application fonts looks bigger and affect layout.

edit:

Both Machines have .Net 2.0 SP2 , but their resolution and screen sizes differ. I understand that fonts physical dimension (on physical screen) will vary with resolution and screen size. But my question is why their dimension in pixel units differ ?

Machine 2 is eeetop ET1602 with windows xp, its touch screen system, by default it came with all desktop fonts bigger, but i have reset windows theme/windows fonts to default.


回答1:


When you secify "Verdana 8.25" , this 8.25 has nothing to do with pixels directly, instead they are considered as "Points" and they will be rendered differently on different machines if the Screen DPI is different.

In Windows, under Desktop settings you have option of increasing the screen font size without changing the resolution. If you increase screen font size then the Dot per pixel changes which can measure different pixel size for same text on different machine.

This is due to fact that old people can not read smaller fonts, thats why they can increase the font size in desktop settings. And you can only specify the font size in points, if font size will be fixed to pixels, it will be difficult for the old or visually impaired people to read the text correctly. This way the text size of entire operating system is in control by the user.




回答2:


This looks like DPI font scaling being set to "large fonts"?

EDIT
See Akash Kava's reply - he goes into more detail on the "large fonts" setting.



来源:https://stackoverflow.com/questions/1944737/net-inconsistent-font-rendering

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!