views:

59

answers:

3

I have written a WinForms program in C# and left the default font for all form controls (labels, checkboxes...) (The font is Tahoma I think, not sure though). When I compile the program and then run it on a Japanese language computer, all the fonts switch to "MS UI Gothic" (a Japanese font).

Is there anyway I can force the font to be the same on all platforms? Currently it messes up the layout a lot, as the characters have a different width depending on the font...

A: 

You can set the font in the form explicitly, via the Font property. I am not sure what the reaction will be if the font is not available on the computer, however.

Steve Ellinger
+2  A: 

As has already been mentioned in the comments, the real solution is to make sure that your form layout can handle different fonts and font sizes. After all, even English users will sometimes change the font size in their Control Panel.

That said, you can force a font by setting the Font property on the form. Most (if not all) controls will inherit the font from the Form if they don’t have an explicit font of their own set. Thus, you could set a Font explicitly in the forms designer, or — if you want the exact font determined at run-time — in the constructor after the call to InitializeComponent(). But when you do this, be aware that ① this will cause an exception if the font doesn’t exist on another machine; and ② you are making it harder for your software to be internationalised in the future.

Timwi
One problem with this the suggested approach is that controls that have a custom size or style will not inherit the typeface either.
romkyns
A: 

If your program is going to run on a different-language OS, you should account for this as much as possible up-front. Here's a good starter article from MSDN - Globalization Step-by-Step and in particular Globalization Step-by-Step Fonts

Otaku