Solve the interface confusion of WinForm program in different resolution system

Source: Internet
Author: User

Problem Analysis:

The main reason for the interface confusion is that the coordinates of the WinForm program are point-based, and the dot is dpi-related, specifically

One inch =72points

An inch = 96pixels96dpi is the default DPI of Windows, and when it is changed by the user, it may cause the interface and design to become confused.

After searching the Internet for relevant information, try to apply this. AutoScaleMode = System.Windows.Forms.AutoScaleMode. Dpi But after the actual measurement, it still doesn't solve the problem: some of the interfaces are not even displayed, and some controls are even "truncated" or not displayed at all.

The reason is: By default, the font unit of Winfrom is point, and the dimensions that are ultimately displayed on the interface are automatically changed according to the DPI setting and can be represented as formulas: point/72 * DPI = Pixel as explained by MSDN, The above settings are appropriate for the visual area of the care program and the control text will always show the design-time size at different dpi, without concern for the absolute size of the program interface.

Workaround:

Later thought that the common unit in the Web program is the pixel (pixel), on the different machines can also be good to render the page layout. So if you can also use pixels in the WinForm program to locate, the problem does not solve it?

Indeed, it is very simple to implement this unit of measure in WinForm, simply by setting the following in the constructor of the form:

123456789101112 privatevoidInitializeComponent() {                         //设定按字体来缩放控件              this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;            //设定字体大小为12px                 this.Font = newSystem.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); }

  

Solve the interface confusion of WinForm program in different resolution system

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.