How does Mono's WinForms determine the system font size?
I wrote a C# application for Linux that is compiled by mono (gmcs
) and uses the WinForms 2.0 library render a user interface. My application looks fine on my computer, but one of my customers is a using a computer (a Fedora/OLPC) with a large font size, and the auto scaling did not totally work for him (text got bigger while user control sizes stayed the same).
If I could increase my font size and reproduce the problem on my Ubuntu computer, I'm sure I could fix the problem (by setting the right AutoScaleMode and AutoScaleDimensions for all of my controls). But when I try to increase my system font size in the System -> Preferences -> Appearance dialog, my font size settings do not seem to have any effect on the Winforms-rendered UI.
So, how does Mono Wi开发者_StackOverflownForms determine the system font size? How can I make it choose a bigger size on my computer?
I am using Ubuntu 9.10 and Mono winforms 2.4.2.3+dfsg-2.
In case it matters, my application was ported from Visual Studio so the fonts on the control are set in .Designer.cs files like so:
label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
You are probably best off disabling AutoScaling:
http://www.mono-project.com/FAQ:_Winforms
(Hans Passant gave the correct answer to this question, but his answer is no longer here, so I will answer my own question.)
The font size used by Mono Winforms is determined by the Resolution (DPI) setting in Ubuntu, which can be accessed by going to System -> Preferences -> Appearance -> Fonts -> Details.
More common answer is: according to my experimentation, Mono calculates actual font size based on Xft.dpi
value. It can be obtained using xrdb -query Xft.dpi
and it can be dynamically set at run-time using echo Xft.dpi: VALUE | xrdb
.
Note that some apps update their UI immediately after changing the value, and others (including Mono) check it only on startup.
Ubuntu's System -> Preferences -> Appearance -> Fonts -> Details
setting mentioned in David Grayson's answer will most likely change the same value.
精彩评论