views:

27

answers:

1

We have a Japanese user reporting that a form size is truncated (smaller size, not all controls are shown) on his Japanese machine. In the windows form .designer.cs file, we have these settings:

     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

Moreover, in the form ctor, we have some code that look like that to adjust the form size to the DPI. uThe japanese user has a regular DPI set o 96.

     //
     // Adjust Form Size from DPIRatio
     //
     var size = this.Size; 
     // dpiRatio is 1.0 if DPI is 96, 
     // dpiRatio is less than 1.0 if DPI higher than 96
     var dpiRatio = DPIHelper.DPIRatio;  
     var newSize = new Size((int)(size.Width/dpiRatio), (int)(size.Height/dpiRatio));
     this.MaximumSize = newSize;
     this.MinimumSize = newSize;
     this.Size = newSize;

I am sure that it comes from the different set of font on Japanese Windows but didn't find any guidance to follow to handle that on the web. Any idea?

+1  A: 

It's the code in the 2nd snippet that messes this up. East Asian machines often take advantage of a XP feature that allows increasing the system font size without also increasing the DPI. Nice for readability of their intricate characters.

Just remove the code to solve the problem. If you want to make the form unsizable then set its FormBorderStyle to, say, Fixed3D. If you do insist on faking the border then you'll have to move the Min/MaximumSize assignments to the Load event. Only then is the form's Size property calculated and corrected for the system font size as well as any user preferences like the size of the border or the size of the caption text. Which btw is another failure mode for your code.

Hans Passant
Hans, thanks for the feedback. This DPI code is here for something: without it the form is not well sized on Wnd machine with DPI set higher than 96. Do you have ideas on handling nicely both higher DPI and Japanese machines?
Patrick Smacchia - NDepend dev
A higher DPI also selects a larger system font size. So the AutoScaleMode takes care of the form size, making it larger. I don't understand why you need it. Make sure to let the machine reboot when you change the DPI setting.
Hans Passant
Hans, indeed what you've written is the theory, but in practice without this DPI code this just don't work. We had tons of Wnd compatibility issue on hings that should work fine in theory http://codebetter.com/blogs/patricksmacchia/archive/2010/04/06/windows-programming-the-quot-it-works-on-my-machine-quot-syndroma.aspx
Patrick Smacchia - NDepend dev
Hmm, coming up with code to fix these perceived universal problems and getting the code wrong doesn't help either. You still haven't explained why it 'just don't work'.
Hans Passant
Hans, actually you were right from the beginning. We had the opportunity to test on a Japanese machine and indeed, removing:
Patrick Smacchia - NDepend dev
DPI code, Maximum/Minimum size trick, and setting the border to FixedSingle did the trick, thanks for your help!
Patrick Smacchia - NDepend dev