From 3fe1a5bf1767c57879d99b60da61b98c94066e0f Mon Sep 17 00:00:00 2001 From: Sunny Date: Thu, 17 Aug 2023 23:25:17 +0800 Subject: [PATCH] =?UTF-8?q?*=20UITextBox:=20=E4=BF=AE=E5=A4=8D=E4=BA=86Ena?= =?UTF-8?q?bled=E4=B8=BAfalse=E6=97=B6=EF=BC=8C=E5=AD=97=E4=BD=93=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E8=B0=83=E6=95=B4=E5=90=8E=EF=BC=8C=E6=96=87=E5=AD=97?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=BD=8D=E7=BD=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UIEdit.cs | 32 -------------------------------- SunnyUI/Controls/UITextBox.cs | 31 ++++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/SunnyUI/Controls/UIEdit.cs b/SunnyUI/Controls/UIEdit.cs index 35cc246c..e46e427a 100644 --- a/SunnyUI/Controls/UIEdit.cs +++ b/SunnyUI/Controls/UIEdit.cs @@ -55,16 +55,6 @@ namespace Sunny.UI this.TextChanged += new EventHandler(ThisTextChanged); } - /// - /// Enable属性变更 - /// - /// - protected override void OnEnabledChanged(EventArgs e) - { - SetStyle(ControlStyles.UserPaint, !Enabled); - base.OnEnabledChanged(e); - } - private void DrawWaterMark() { if (this.waterMarkContainer == null && this.TextLength <= 0) @@ -168,28 +158,6 @@ namespace Sunny.UI { base.OnPaint(e); DrawWaterMark(); - - if (Text.IsValid() && !Enabled) - { - string text = Text; - if (PasswordChar > 0) - { - text = PasswordChar.ToString().Repeat(text.Length); - } - - if (TextAlign == HorizontalAlignment.Left) - { - e.Graphics.DrawString(text, Font, ForeDisableColor, new Rectangle(0, 0, Width, Height), ContentAlignment.MiddleLeft, -5, 0); - } - else if (TextAlign == HorizontalAlignment.Right) - { - e.Graphics.DrawString(text, Font, ForeDisableColor, new Rectangle(0, 0, Width, Height), ContentAlignment.MiddleRight, 7, 0); - } - else - { - e.Graphics.DrawString(text, Font, ForeDisableColor, new Rectangle(0, 0, Width, Height), ContentAlignment.MiddleCenter, 1, 0); - } - } } public virtual Color ForeDisableColor { get; set; } = Color.FromArgb(109, 109, 103); diff --git a/SunnyUI/Controls/UITextBox.cs b/SunnyUI/Controls/UITextBox.cs index 572cc077..91ecf1ef 100644 --- a/SunnyUI/Controls/UITextBox.cs +++ b/SunnyUI/Controls/UITextBox.cs @@ -49,6 +49,7 @@ * 2023-06-14: V3.3.9 按钮图标位置修正 * 2023-07-03: V3.3.9 增加Enabled为false时,可修改文字颜色 * 2023-07-16: V3.4.0 修复了Enabled为false时,PasswordChar失效的问题 + * 2023-08-17: V3.4.1 修复了Enabled为false时,字体大小调整后,文字显示位置的问题 ******************************************************************************/ using System; @@ -412,7 +413,7 @@ namespace Sunny.UI { base.OnEnabledChanged(e); edit.BackColor = GetFillColor(); - edit.Enabled = Enabled; + edit.Visible = Enabled; } public override bool Focused => edit.Focused; @@ -1269,6 +1270,34 @@ namespace Sunny.UI { e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor, new Rectangle(4 + symbolOffset.X, (Height - SymbolSize) / 2 + 1 + symbolOffset.Y, SymbolSize, SymbolSize), SymbolOffset.X, SymbolOffset.Y); } + + if (Text.IsValid() && !Enabled) + { + string text = Text; + if (PasswordChar > 0) + { + text = PasswordChar.ToString().Repeat(text.Length); + } + + ContentAlignment textAlign = ContentAlignment.MiddleLeft; + if (TextAlignment == ContentAlignment.TopCenter || TextAlignment == ContentAlignment.MiddleCenter || TextAlignment == ContentAlignment.BottomCenter) + textAlign = ContentAlignment.MiddleCenter; + + if (TextAlignment == ContentAlignment.TopRight || TextAlignment == ContentAlignment.MiddleRight || TextAlignment == ContentAlignment.BottomRight) + textAlign = ContentAlignment.MiddleRight; + + Size sf = TextRenderer.MeasureText(text, edit.Font); + using (Brush br = new SolidBrush(ForeDisableColor)) + { + if (textAlign == ContentAlignment.MiddleLeft) + e.Graphics.DrawString(text, Font, br, new Point(edit.Left + 1 - Math.Min((int)(Font.Size / 3), 4), ((Height - sf.Height) / 2.0).RoundEx() - 1)); + if (textAlign == ContentAlignment.MiddleCenter) + e.Graphics.DrawString(text, Font, br, new Point(edit.Left + (int)((edit.Width - sf.Width) / 2) + (Font.Size < 10 ? 1 : 2), ((Height - sf.Height) / 2.0).RoundEx() - 1)); + if (textAlign == ContentAlignment.MiddleRight) + e.Graphics.DrawString(text, Font, br, new Point(edit.Left + edit.Width - sf.Width - 3 + Math.Min((int)(sf.Height / 2), 10), ((Height - sf.Height) / 2.0).RoundEx() - 1)); + } + + } } public Color _symbolColor = UIFontColor.Primary;