Fixed WinForm style, not changed due to system settings

Source: Internet
Author: User
1. Reason
Because the character set settings of different systems may be different, the. NET Winform applications developed in one environment become incomplete or disordered in the other environment.
2. Solution
Set the AutoScaleMode attribute of Form to None (Font by default), and set the AutoSize attribute of Form to False (False by default)
Solution: set Form AutoSize to True, AutoSizeMode to GrowOnly, and AutoScaleMode to Font to automatically scale the Form and internal controls under different settings.
In Darwine development, we will adopt the first solution to ensure unified Form style.
3. Analysis
See the following MSDN explanation;
How to Set DPI

Appendix:
The form and control can be automatically adjusted in all DPI settings, while keeping the size and position ratio unchanged. To maintain the same ratio (or scale) among multiple DPI settings, two important elements are required. The first element indicates automatic scaling of the form. The second element indicates the scale number applied to the size and position of the form and its controls. By default, the form is scaled automatically through its AutoScale attribute (set to true. The scaling coefficient is specified by the AutoScaleMode attribute. Its value can be one of the following values:

Enum AutoScaleMode {
None = 0, // do not scale
Font = 1, // scale according to the Font size (default)
Dpi = 2, // scale according to dpi
Inherit = 3 // Inherit the AutoScaleMode of the container
}

The default value is Font, indicating that the zoom factor is based on the ratio of the average width and height of the system Font by default when the form is created and executed. For example, if you create a form in a Windows XP Regular font (96 DPI), the default font is 8.25pt MS Sans Serif with an average width and height of 6x13. This information is automatically stored by the Windows Form Designer in the AutoScaleDimensions attribute of the form:

// AutoScalingForm. designer. cs
Partial class AutoScalingForm {
...
Void InitializeComponent (){
...
This. AutoScaleDimensions = new SizeF (6F, 13F );
...
}
}

If you re-open the form or execute the form in a large font (120 DPI) that defaults to 7.8pt MS Sans Serif, the average width and height of the font will be increased to 8x16. The form will notice the difference between AutoScaleDimensions and the current scaling size, and then adjust the width, height, and position of the control based on the calculated difference. In this way, the overall appearance of the form can be roughly the same regardless of the system font settings. The same behavior within Visual Studio will also be consistent.
AutoSizeMode. Font enables zooming Based on the Font differences between DPI, while AutoSizeMode. Dpi enables zooming based entirely on the differences between DPI. The two modes are compared.

Auto scaling from 96 DPI to 120 DPI
AutoScaleMode. font and AutoScaleMode. the difference between Dpi and actual use is that the scaling rate of both the front and back is different, because the scaling method of the proportional font is different from that of the pure linear DPI scaling, this is especially evident in the scaling of different languages. AutoScaleMode. Font is the default option because it is the most reliable option.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.