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 |
private
void
InitializeComponent()
{
//设定按字体来缩放控件
this
.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
//设定字体大小为12px
this
.Font =
new
System.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