From 85a56809f16248d0ff62425ae6e8d88027dffc9f Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 25 Oct 2023 22:30:43 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIDropControl:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=9C=A8=E9=AB=98DPI=E4=B8=8B=EF=BC=8C=E6=96=87=E5=AD=97?= =?UTF-8?q?=E5=9E=82=E7=9B=B4=E4=B8=8D=E5=B1=85=E4=B8=AD=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20*=20UIDropControl:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8?= =?UTF-8?q?=E6=9F=90=E4=BA=9B=E5=AD=97=E4=BD=93=E4=B8=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=B8=8B=E5=88=92=E7=BA=BF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DropItem/UIDropControl.Designer.cs | 4 +- SunnyUI/Controls/DropItem/UIDropControl.cs | 48 +++++++++++++++--- SunnyUI/Controls/DropItem/UIDropControl.resx | 50 +++++++++---------- SunnyUI/Controls/UITextBox.cs | 17 +++---- 4 files changed, 72 insertions(+), 47 deletions(-) diff --git a/SunnyUI/Controls/DropItem/UIDropControl.Designer.cs b/SunnyUI/Controls/DropItem/UIDropControl.Designer.cs index a0c6cc4d..ae37d402 100644 --- a/SunnyUI/Controls/DropItem/UIDropControl.Designer.cs +++ b/SunnyUI/Controls/DropItem/UIDropControl.Designer.cs @@ -36,13 +36,11 @@ // // UIDropControl // - AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F); AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; MinimumSize = new System.Drawing.Size(63, 0); Name = "UIDropControl"; - Size = new System.Drawing.Size(150, 29); + Size = new System.Drawing.Size(194, 29); ResumeLayout(false); - } #endregion diff --git a/SunnyUI/Controls/DropItem/UIDropControl.cs b/SunnyUI/Controls/DropItem/UIDropControl.cs index f731969a..d564cbbe 100644 --- a/SunnyUI/Controls/DropItem/UIDropControl.cs +++ b/SunnyUI/Controls/DropItem/UIDropControl.cs @@ -27,6 +27,8 @@ * 2023-05-16: V3.3.6 重构DrawFontImage函数 * 2023-08-24: V3.4.2 修改背景色后编辑框颜色修复 * 2023-08-28: V3.4.2 下拉框按钮图标增加编辑器 + * 2023-10-25: V3.5.1 修复在高DPI下,文字垂直不居中的问题 + * 2023-10-25: V3.5.1 修复在某些字体不显示下划线的问题 ******************************************************************************/ using System; @@ -47,8 +49,7 @@ namespace Sunny.UI SetStyleFlags(); Padding = new Padding(0, 0, 30, 2); - edit.AutoSize = false; - //edit.Font = UIStyles.Font(); + edit.AutoSize = true; edit.Left = 4; edit.Top = 3; edit.Text = String.Empty; @@ -59,9 +60,14 @@ namespace Sunny.UI edit.KeyUp += EditOnKeyUp; edit.KeyPress += EditOnKeyPress; edit.LostFocus += Edit_LostFocus; + edit.SizeChanged += Edit_SizeChanged; edit.Invalidate(); Controls.Add(edit); + lastEditHeight = edit.Height; + Width = 150; + Height = 29; + TextAlignment = ContentAlignment.MiddleLeft; fillColor = Color.White; edit.BackColor = Color.White; @@ -70,6 +76,16 @@ namespace Sunny.UI ControlBoxRect = new Rectangle(Width - 24, 0, 24, Height); } + int lastEditHeight = -1; + private void Edit_SizeChanged(object sender, EventArgs e) + { + if (lastEditHeight != edit.Height) + { + lastEditHeight = edit.Height; + SizeChange(); + } + } + public override void SetDPIScale() { base.SetDPIScale(); @@ -87,7 +103,6 @@ namespace Sunny.UI { base.OnFontChanged(e); if (DefaultFontSize < 0 && edit != null) edit.Font = this.Font; - SizeChange(); Invalidate(); } @@ -371,19 +386,36 @@ namespace Sunny.UI /// 参数 protected override void OnSizeChanged(EventArgs e) { - SizeChange(); + base.OnSizeChanged(e); + + if (!NoNeedChange) + { + SizeChange(); + } + if (tipsBtn != null) { tipsBtn.Location = new System.Drawing.Point(Width - 8, 2); } } + private bool NoNeedChange = false; + private void SizeChange() { - if (Height < UIGlobal.EditorMinHeight) Height = UIGlobal.EditorMinHeight; - if (Height > UIGlobal.EditorMaxHeight) Height = UIGlobal.EditorMaxHeight; - edit.Height = Math.Min(Height - RectSize * 2, edit.PreferredHeight); - edit.Top = (Height - edit.Height) / 2; + if (Height < edit.Height + RectSize * 2 + 2) + { + NoNeedChange = true; + Height = edit.Height + RectSize * 2 + 2; + edit.Top = (Height - edit.Height) / 2; + NoNeedChange = false; + } + + if (edit.Top != (Height - edit.Height) / 2 + 1) + { + edit.Top = (Height - edit.Height) / 2 + 1; + } + edit.Left = 4 + Padding.Left; edit.Width = Width - Padding.Left - Padding.Right - 4; ControlBoxRect = new Rectangle(Width - 24, 0, 24, Height); diff --git a/SunnyUI/Controls/DropItem/UIDropControl.resx b/SunnyUI/Controls/DropItem/UIDropControl.resx index 1af7de15..af32865e 100644 --- a/SunnyUI/Controls/DropItem/UIDropControl.resx +++ b/SunnyUI/Controls/DropItem/UIDropControl.resx @@ -1,17 +1,17 @@  - diff --git a/SunnyUI/Controls/UITextBox.cs b/SunnyUI/Controls/UITextBox.cs index 0f306368..3cdc497c 100644 --- a/SunnyUI/Controls/UITextBox.cs +++ b/SunnyUI/Controls/UITextBox.cs @@ -109,9 +109,6 @@ namespace Sunny.UI edit.MouseDoubleClick += Edit_MouseDoubleClick; edit.SizeChanged += Edit_SizeChanged; - Width = 150; - Height = 29; - btn.Parent = this; btn.Visible = false; btn.Text = ""; @@ -135,8 +132,10 @@ namespace Sunny.UI bar.MouseEnter += Bar_MouseEnter; TextAlignment = ContentAlignment.MiddleLeft; - SizeChange(); lastEditHeight = edit.Height; + Width = 150; + Height = 29; + editCursor = Cursor; TextAlignmentChange += UITextBox_TextAlignmentChange; } @@ -674,12 +673,8 @@ namespace Sunny.UI base.OnFontChanged(e); if (DefaultFontSize < 0 && edit != null) - { edit.Font = this.Font; - edit.Invalidate(); - } - SizeChange(); Invalidate(); } @@ -739,9 +734,9 @@ namespace Sunny.UI NoNeedChange = false; } - if (edit.Top != (Height - edit.Height) / 2) + if (edit.Top != (Height - edit.Height) / 2 + 1) { - edit.Top = (Height - edit.Height) / 2; + edit.Top = (Height - edit.Height) / 2 + 1; } if (icon == null && Symbol == 0) @@ -783,7 +778,7 @@ namespace Sunny.UI int barWidth = Math.Max(ScrollBarInfo.VerticalScrollBarWidth() + 1, ScrollBarWidth); bar.Top = 2; bar.Width = barWidth; - bar.Left = Width - bar.Width - 1; + bar.Left = Width - bar.Width - 2; bar.Height = Height - 4; bar.BringToFront();