From da1f4fb54c792a35e2020f43cca3096492fc23bf Mon Sep 17 00:00:00 2001 From: hlz2516 <714251494@qq.com> Date: Sat, 25 Nov 2023 14:56:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=97=E4=BD=93=E7=BC=A9?= =?UTF-8?q?=E6=94=BE=E6=97=B6=E9=A3=8E=E6=A0=BC=E6=B6=88=E5=A4=B1=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutoScaleHelper/AutoScale.cs | 5 ++-- AutoScaleHelper/TextScale.cs | 7 +++-- .../FontScaleForm1.Designer.cs" | 16 +++++------ .../FontScaleForm2.Designer.cs" | 28 +++++++++---------- .../Form_Textbox.Designer.cs" | 4 +-- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/AutoScaleHelper/AutoScale.cs b/AutoScaleHelper/AutoScale.cs index 0dc0fef..9724f78 100644 --- a/AutoScaleHelper/AutoScale.cs +++ b/AutoScaleHelper/AutoScale.cs @@ -308,7 +308,7 @@ public void UpdateControlsLayout(bool recursive = true) int fontHeight = (int)(ctrlInfo.Font.Height * 1.0f / ctrlInfo.Rect.Height * curCtrl.Height); FontInfo fontInfo = FontInfos.GetFontInfo(ctrlInfo.Font.Name); float fontSize = fontInfo.GetFloorFontSizeByHeight(fontHeight, ctrlInfo.FontSizeType); - curCtrl.Font = new Font(ctrlInfo.Font.Name, fontSize); + curCtrl.Font = new Font(ctrlInfo.Font.Name, fontSize,ctrlInfo.Font.Style); } } @@ -323,7 +323,8 @@ public void UpdateControlsLayout(bool recursive = true) { foreach (var item in g.Value) { - item.Font = g.Key.Font.Clone() as Font; + //item.Font = g.Key.Font.Clone() as Font; + item.Font = new Font(g.Key.Font.FontFamily, g.Key.Font.Size, item.Font.Style); } } diff --git a/AutoScaleHelper/TextScale.cs b/AutoScaleHelper/TextScale.cs index 407f2d7..b388abf 100644 --- a/AutoScaleHelper/TextScale.cs +++ b/AutoScaleHelper/TextScale.cs @@ -114,7 +114,7 @@ public void ScaleSingle(Control ctrl,ScaleMode scaleMode = ScaleMode.MaintainSel int fontHeight = (int)(ctrlInfo.Font.Height * 1.0f / ctrlInfo.Rect.Height * ctrl.Height); FontInfo fontInfo = FontInfos.GetFontInfo(ctrlInfo.Font.Name); float fontSize = fontInfo.GetFloorFontSizeByHeight(fontHeight, ctrlInfo.FontSizeType); - ctrl.Font = new Font(ctrlInfo.Font.Name, fontSize); + ctrl.Font = new Font(ctrlInfo.Font.Name, fontSize,ctrl.Font.Style); } else if (scaleMode == ScaleMode.MaintainSelfRatioH) { @@ -122,7 +122,7 @@ public void ScaleSingle(Control ctrl,ScaleMode scaleMode = ScaleMode.MaintainSel float rate = ctrl.Width * 1.0f / ctrlInfo.Rect.Width; FontInfo fontInfo = FontInfos.GetFontInfo(ctrlInfo.Font.Name); float fontSize = fontInfo.GetFloorFontSizeByHeight((int)(rate * ctrlInfo.Font.Height), ctrlInfo.FontSizeType); - ctrl.Font = new Font(ctrlInfo.Font.Name, fontSize); + ctrl.Font = new Font(ctrlInfo.Font.Name, fontSize,ctrl.Font.Style); } //针对设置了字体依赖的控件特殊处理 @@ -131,7 +131,8 @@ public void ScaleSingle(Control ctrl,ScaleMode scaleMode = ScaleMode.MaintainSel var values = groups[ctrl]; foreach (var item in values) { - item.Font = ctrl.Font.Clone() as Font; + //item.Font = ctrl.Font.Clone() as Font; + item.Font = new Font(ctrl.Font.FontFamily, ctrl.Font.Size, item.Font.Style); } } } diff --git "a/Demo/6_\345\255\227\344\275\223\350\207\252\351\200\202\345\272\224/FontScaleForm1.Designer.cs" "b/Demo/6_\345\255\227\344\275\223\350\207\252\351\200\202\345\272\224/FontScaleForm1.Designer.cs" index e83d869..bc7fbac 100644 --- "a/Demo/6_\345\255\227\344\275\223\350\207\252\351\200\202\345\272\224/FontScaleForm1.Designer.cs" +++ "b/Demo/6_\345\255\227\344\275\223\350\207\252\351\200\202\345\272\224/FontScaleForm1.Designer.cs" @@ -42,7 +42,7 @@ private void InitializeComponent() // // button1 // - this.button1.Font = new System.Drawing.Font("宋体", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button1.Font = new System.Drawing.Font("宋体", 26.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.button1.Location = new System.Drawing.Point(43, 38); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(228, 107); @@ -52,7 +52,7 @@ private void InitializeComponent() // // button2 // - this.button2.Font = new System.Drawing.Font("宋体", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button2.Font = new System.Drawing.Font("宋体", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.button2.Location = new System.Drawing.Point(319, 61); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(202, 84); @@ -62,7 +62,7 @@ private void InitializeComponent() // // button3 // - this.button3.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button3.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.button3.Location = new System.Drawing.Point(571, 88); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(159, 57); @@ -72,7 +72,7 @@ private void InitializeComponent() // // button4 // - this.button4.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button4.Font = new System.Drawing.Font("仿宋", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.button4.Location = new System.Drawing.Point(790, 105); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(107, 40); @@ -92,7 +92,7 @@ private void InitializeComponent() // // button6 // - this.button6.Font = new System.Drawing.Font("微软雅黑", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button6.Font = new System.Drawing.Font("微软雅黑 Light", 48F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.button6.Location = new System.Drawing.Point(43, 309); this.button6.Name = "button6"; this.button6.Size = new System.Drawing.Size(228, 107); @@ -102,7 +102,7 @@ private void InitializeComponent() // // button7 // - this.button7.Font = new System.Drawing.Font("微软雅黑", 27.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button7.Font = new System.Drawing.Font("Yu Gothic UI", 27.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.button7.Location = new System.Drawing.Point(319, 332); this.button7.Name = "button7"; this.button7.Size = new System.Drawing.Size(202, 84); @@ -112,7 +112,7 @@ private void InitializeComponent() // // button8 // - this.button8.Font = new System.Drawing.Font("微软雅黑", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button8.Font = new System.Drawing.Font("微软雅黑", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.button8.Location = new System.Drawing.Point(571, 359); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(159, 57); @@ -122,7 +122,7 @@ private void InitializeComponent() // // button9 // - this.button9.Font = new System.Drawing.Font("微软雅黑", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button9.Font = new System.Drawing.Font("微软雅黑 Light", 9.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.button9.Location = new System.Drawing.Point(790, 376); this.button9.Name = "button9"; this.button9.Size = new System.Drawing.Size(107, 40); diff --git "a/Demo/6_\345\255\227\344\275\223\350\207\252\351\200\202\345\272\224/FontScaleForm2.Designer.cs" "b/Demo/6_\345\255\227\344\275\223\350\207\252\351\200\202\345\272\224/FontScaleForm2.Designer.cs" index 28ae704..832b1df 100644 --- "a/Demo/6_\345\255\227\344\275\223\350\207\252\351\200\202\345\272\224/FontScaleForm2.Designer.cs" +++ "b/Demo/6_\345\255\227\344\275\223\350\207\252\351\200\202\345\272\224/FontScaleForm2.Designer.cs" @@ -30,8 +30,8 @@ private void InitializeComponent() { this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.tableLayoutPanel1.SuspendLayout(); this.SuspendLayout(); @@ -68,18 +68,6 @@ private void InitializeComponent() this.label1.Text = "label1"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label2 - // - this.label2.AutoSize = true; - this.label2.Dock = System.Windows.Forms.DockStyle.Fill; - this.label2.Font = new System.Drawing.Font("宋体", 27.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label2.Location = new System.Drawing.Point(470, 1); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(460, 274); - this.label2.TabIndex = 2; - this.label2.Text = "label2"; - this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // // label3 // this.label3.AutoSize = true; @@ -92,10 +80,22 @@ private void InitializeComponent() this.label3.Text = "label3"; this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // + // label2 + // + this.label2.AutoSize = true; + this.label2.Dock = System.Windows.Forms.DockStyle.Fill; + this.label2.Font = new System.Drawing.Font("宋体", 27.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label2.Location = new System.Drawing.Point(470, 1); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(460, 274); + this.label2.TabIndex = 2; + this.label2.Text = "label2"; + this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // // comboBox1 // this.comboBox1.Dock = System.Windows.Forms.DockStyle.Fill; - this.comboBox1.Font = new System.Drawing.Font("宋体", 27.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.comboBox1.Font = new System.Drawing.Font("宋体", 27.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(470, 279); this.comboBox1.Name = "comboBox1"; diff --git "a/Demo/7_\345\270\270\347\224\250\346\216\247\344\273\266\346\265\213\350\257\225/Form_Textbox.Designer.cs" "b/Demo/7_\345\270\270\347\224\250\346\216\247\344\273\266\346\265\213\350\257\225/Form_Textbox.Designer.cs" index caeb11e..5901343 100644 --- "a/Demo/7_\345\270\270\347\224\250\346\216\247\344\273\266\346\265\213\350\257\225/Form_Textbox.Designer.cs" +++ "b/Demo/7_\345\270\270\347\224\250\346\216\247\344\273\266\346\265\213\350\257\225/Form_Textbox.Designer.cs" @@ -79,7 +79,7 @@ private void InitializeComponent() // textBox3 // this.textBox3.Anchor = System.Windows.Forms.AnchorStyles.None; - this.textBox3.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.textBox3.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.textBox3.Location = new System.Drawing.Point(100, 176); this.textBox3.Name = "textBox3"; this.textBox3.Size = new System.Drawing.Size(171, 31); @@ -89,7 +89,7 @@ private void InitializeComponent() // textBox4 // this.textBox4.Anchor = System.Windows.Forms.AnchorStyles.None; - this.textBox4.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.textBox4.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.textBox4.Location = new System.Drawing.Point(100, 242); this.textBox4.Multiline = true; this.textBox4.Name = "textBox4";