Recently, when I was working on a project, the developed winform can be normally displayed on my computer. If I share it with another computer, I cannot display it:
1. When the resolution of the two computers is the same, the display cannot be completely displayed. Check whether the autoscalemode attribute of form is none and set it to none.
2. When the resolution is different, you can directly call the initialization function in the form constructor and add AutoReSizeForm. SetFormSize (this); (this is also applicable to user control)
Public class AutoReSizeForm
{
Static float SH
{
Get
{
Return (float) Screen. PrimaryScreen. Bounds. Height/Properties. Settings. Default. Y;
}
}
Static float SW
{
Get
{
Return (float) Screen. PrimaryScreen. Bounds. Width/Properties. Settings. Default. X;
}
}
Public static void SetFormSize (Control fm)
{
Fm. Location = new Point (int) (fm. Location. X * SW), (int) (fm. Location. Y * SH ));
Fm. Size = new Size (int) (fm. Size. Width * SW), (int) (fm. Size. Height * SH ));
Fm. font = new Font (fm. font. name, fm. font. size * SH, fm. font. style, fm. font. unit, fm. font. gdiCharSet, fm. font. gdiVerticalFont );
If (fm. Controls. Count! = 0)
{
SetControlSize (fm );
}
}
Private static void SetControlSize (Control InitC)
{
Foreach (Control c in InitC. Controls)
{
C. Location = new Point (int) (c. Location. X * SW), (int) (c. Location. Y * SH ));
C. Size = new Size (int) (c. Size. Width * SW), (int) (c. Size. Height * SH ));
C. font = new Font (c. font. name, c. font. size * SH, c. font. style, c. font. unit, c. font. gdiCharSet, c. font. gdiVerticalFont );
If (c. Controls. Count! = 0)
{
SetControlSize (c );
}
}
}
}