日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > C# >内容正文

C#

c# winform窗口自适应各种分辨率类

發(fā)布時間:2025/1/21 C# 89 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c# winform窗口自适应各种分辨率类 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1 近期做項目時,遇到開發(fā)的winform在自己電腦上可以正常顯示,共享到其他電腦就事兒不能顯示了: 2 3 1.當(dāng)兩個電腦分辨率相同時,無法顯示完全,請檢查form的autoscalemode屬性是否為none,并設(shè)為none 4 5 2.分辨率不同時,可直接在form的構(gòu)造函數(shù)中調(diào)用初始化函數(shù)之后, 加上一句AutoReSizeForm. SetFormSize(this);(對于自定義控件usercontrol也適用) 6 7 public class AutoReSizeForm 8 9 { 10 static float SH 11 { 12 get 13 { 14 return (float)Screen.PrimaryScreen.Bounds.Height / Properties.Settings.Default.Y; 15 } 16 } 17 static float SW 18 { 19 get 20 { 21 return (float)Screen.PrimaryScreen.Bounds.Width / Properties.Settings.Default.X; 22 } 23 } 24 25 26 27 28 public static void SetFormSize(Control fm) 29 { 30 fm.Location = new Point((int)(fm.Location.X * SW), (int)(fm.Location.Y * SH)); 31 fm.Size = new Size((int)(fm.Size.Width * SW), (int)(fm.Size.Height * SH)); 32 fm.Font = new Font(fm.Font.Name, fm.Font.Size * SH,fm.Font.Style,fm.Font.Unit,fm.Font.GdiCharSet,fm.Font.GdiVerticalFont); 33 if (fm.Controls.Count!=0) 34 { 35 SetControlSize(fm); 36 } 37 } 38 39 40 private static void SetControlSize(Control InitC) 41 { 42 foreach (Control c in InitC.Controls) 43 { 44 c.Location = new Point((int)(c.Location.X * SW), (int)(c.Location.Y * SH)); 45 c.Size = new Size((int)(c.Size.Width * SW), (int)(c.Size.Height * SH)); 46 c.Font = new Font(c.Font.Name, c.Font.Size * SH, c.Font.Style, c.Font.Unit, c.Font.GdiCharSet, c.Font.GdiVerticalFont); 47 if (c.Controls.Count != 0) 48 { 49 SetControlSize(c); 50 } 51 } 52 } 53 }

?

總結(jié)

以上是生活随笔為你收集整理的c# winform窗口自适应各种分辨率类的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。